Back to index

salome-geom  6.5.0
GEOMToolsGUI_1.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  GEOM GEOMGUI : GUI for Geometry component
00024 //  File   : GEOMToolsGUI_1.cxx
00025 //  Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
00026 
00027 #include <PyConsole_Console.h>
00028 
00029 #include "GEOMToolsGUI.h"
00030 #include "GEOMToolsGUI_TransparencyDlg.h"
00031 #include "GEOMToolsGUI_NbIsosDlg.h"
00032 #include "GEOMToolsGUI_DeflectionDlg.h"
00033 #include "GEOMToolsGUI_MarkerDlg.h"
00034 #include "GEOMToolsGUI_PublishDlg.h"
00035 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
00036 #include "GEOMToolsGUI_LineWidthDlg.h"
00037 #include "Material_Model.h"
00038 
00039 #include <GeometryGUI.h>
00040 #include <GeometryGUI_Operations.h>
00041 #include <GEOM_Constants.h>
00042 #include <GEOM_Displayer.h>
00043 
00044 #include <GEOMBase.h>
00045 #include <GEOM_Actor.h>
00046 
00047 #include <Basics_OCCTVersion.hxx>
00048 
00049 #include <SALOME_ListIO.hxx>
00050 #include <SALOME_ListIteratorOfListIO.hxx>
00051 
00052 #include <SOCC_Prs.h>
00053 
00054 #include <SVTK_Prs.h>
00055 #include <SVTK_ViewModel.h>
00056 #include <SVTK_ViewWindow.h>
00057 #include <SVTK_View.h>
00058 
00059 #include <OCCViewer_ViewModel.h>
00060 
00061 #include <SUIT_ViewManager.h>
00062 #include <SUIT_Desktop.h>
00063 #include <SUIT_ResourceMgr.h>
00064 #include <SUIT_Session.h>
00065 #include <SUIT_OverrideCursor.h>
00066 #include <SUIT_MessageBox.h>
00067 #include <SUIT_Tools.h>
00068 
00069 #include <SalomeApp_Application.h>
00070 #include <SalomeApp_Study.h>
00071 #include <SalomeApp_Module.h>
00072 
00073 #include <LightApp_SelectionMgr.h>
00074 #include <LightApp_NameDlg.h>
00075 
00076 #include <GEOMImpl_Types.hxx>
00077 
00078 #include "utilities.h"
00079 
00080 // OCCT Includes
00081 #include <AIS_Drawer.hxx>
00082 #include <Prs3d_IsoAspect.hxx>
00083 #include <Prs3d_PointAspect.hxx>
00084 #include <Graphic3d_AspectMarker3d.hxx>
00085 #include <Graphic3d_AspectLine3d.hxx>
00086 #include <AIS_ListIteratorOfListOfInteractive.hxx>
00087 #include <AIS_ListOfInteractive.hxx>
00088 
00089 
00090 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00091 #include <TColStd_HArray1OfByte.hxx>
00092 #else
00093 #include <Graphic3d_HArray1OfBytes.hxx>
00094 #endif
00095 
00096 // QT Includes
00097 #include <QAction>
00098 #include <QColorDialog>
00099 #include <QInputDialog>
00100 #include <QFileDialog>
00101 #include <QList>
00102 
00103 #include <QGridLayout>
00104 #include <QGroupBox>
00105 #include <QSpinBox>
00106 #include <QPushButton>
00107 #include <QKeyEvent>
00108 
00109 // VTK includes
00110 #include <vtkRenderer.h>
00111 
00112 void GEOMToolsGUI::OnCheckGeometry()
00113 {
00114   SalomeApp_Application* app =
00115     dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
00116   PyConsole_Console* pyConsole = app->pythonConsole();
00117 
00118   if (pyConsole)
00119     pyConsole->exec("from GEOM_usinggeom import *");
00120 }
00121 
00122 void GEOMToolsGUI::OnAutoColor()
00123 {
00124   SALOME_ListIO selected;
00125   SalomeApp_Application* app =
00126     dynamic_cast< SalomeApp_Application* >(SUIT_Session::session()->activeApplication());
00127   if (!app)
00128     return;
00129 
00130   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00131   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
00132   if (!aSelMgr || !appStudy)
00133     return;
00134 
00135   aSelMgr->selectedObjects(selected);
00136   if (selected.IsEmpty())
00137     return;
00138 
00139   Handle(SALOME_InteractiveObject) anIObject = selected.First();
00140 
00141   _PTR(Study) aStudy = appStudy->studyDS();
00142   _PTR(SObject) aMainSObject(aStudy->FindObjectID(anIObject->getEntry()));
00143   GEOM::GEOM_Object_var aMainObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
00144   if (CORBA::is_nil(aMainObject))
00145     return;
00146 
00147   aMainObject->SetAutoColor( true );
00148 
00149   QList<SALOMEDS::Color> aReservedColors;
00150 
00151   GEOM_Displayer aDisp (appStudy);
00152 
00153   SALOME_View* vf = aDisp.GetActiveView();
00154 
00155   SUIT_ViewWindow* window = app->desktop()->activeWindow();
00156   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
00157   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
00158 
00159   for( _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); it->More(); it->Next() )
00160   {
00161     _PTR(SObject) aChildSObject( it->Value() );
00162     GEOM::GEOM_Object_var aChildObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
00163     if( CORBA::is_nil( aChildObject ) )
00164       continue;
00165 
00166     if( aChildObject->GetType() != GEOM_GROUP )
00167       continue;
00168 
00169     SALOMEDS::Color aColor = GEOM_Displayer::getUniqueColor( aReservedColors );
00170     aChildObject->SetColor( aColor );
00171     aReservedColors.append( aColor );
00172 
00173     QColor c( (int)( aColor.R * 255.0 ), (int)( aColor.G * 255.0 ), (int)( aColor.B * 255.0 ) );
00174 
00175     SALOME_Prs* aPrs = vf->CreatePrs( aChildSObject->GetID().c_str() );
00176 
00177     if ( isVTK )
00178     {
00179       SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
00180       if ( !vtkVW )
00181         return;
00182       SVTK_View* aView = vtkVW->getView();
00183       SUIT_OverrideCursor();
00184       for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() )
00185         aView->SetColor( It.Value(), c );
00186     }
00187     else if ( isOCC )
00188     {
00189       OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
00190       Handle(AIS_InteractiveContext) ic = vm->getAISContext();
00191 
00192       SOCC_Prs* anOCCPrs = dynamic_cast<SOCC_Prs*>( aPrs );
00193       if( !anOCCPrs )
00194         continue;
00195 
00196       AIS_ListOfInteractive aList;
00197       anOCCPrs->GetObjects( aList );
00198       if( !aList.Extent() )
00199         continue;
00200 
00201       Handle(AIS_InteractiveObject) io = aList.First();
00202       if( io.IsNull() )
00203         continue;
00204 
00205       Quantity_Color aQuanColor( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
00206 
00207       // Set color for a point
00208       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
00209       Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
00210       Quantity_Color aCurColor;
00211       Standard_Real aCurScale;
00212       Aspect_TypeOfMarker aCurTypeOfMarker;
00213       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
00214       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
00215         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aQuanColor, aCurScale) );
00216       }
00217       else {
00218         Standard_Integer aWidth, aHeight;
00219         aCurPointAspect->GetTextureSize( aWidth, aHeight );
00220 
00221 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00222         Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
00223 #else
00224         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
00225 #endif
00226 
00227         aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aQuanColor, 1, aWidth, aHeight, aTexture ) );
00228       }
00229       ic->SetLocalAttributes( io, aCurDrawer );
00230 
00231       io->SetColor( aQuanColor );
00232       if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
00233        Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
00234         aGAISShape->SetShadingColor( aQuanColor );
00235        aGAISShape->storeBoundaryColors();
00236       }
00237 
00238       io->Redisplay( Standard_True );
00239     }
00240   }
00241 
00242   app->updateActions(); //SRN: To update a Save button in the toolbar
00243 }
00244 
00245 void GEOMToolsGUI::OnDisableAutoColor()
00246 {
00247   SALOME_ListIO selected;
00248   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00249   if( !app )
00250     return;
00251 
00252   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00253   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00254   if( !aSelMgr || !appStudy )
00255     return;
00256 
00257   aSelMgr->selectedObjects( selected );
00258   if( selected.IsEmpty() )
00259     return;
00260 
00261   Handle(SALOME_InteractiveObject) anIObject = selected.First();
00262 
00263   _PTR(Study) aStudy = appStudy->studyDS();
00264   _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
00265   GEOM::GEOM_Object_var aMainObject =  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aMainSObject));
00266   if( CORBA::is_nil( aMainObject ) )
00267     return;
00268 
00269   aMainObject->SetAutoColor( false );
00270 
00271 }
00272 
00273 void GEOMToolsGUI::OnColor()
00274 {
00275   SALOME_ListIO selected;
00276   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00277   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00278   if ( app && appStudy ) {
00279     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00280     if ( aSelMgr ) {
00281       aSelMgr->selectedObjects( selected );
00282       if ( !selected.IsEmpty() ) {
00283         SUIT_ViewWindow* window = app->desktop()->activeWindow();
00284         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
00285         bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
00286         int mgrId = window->getViewManager()->getGlobalId();
00287         if ( isVTK ) {
00288           SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
00289           if ( !vtkVW )
00290             return;
00291           SVTK_View* aView = vtkVW->getView();
00292           QColor initcolor = aView->GetColor( selected.First()  );
00293           QColor c = QColorDialog::getColor( initcolor, app->desktop() );
00294           if ( c.isValid() ) {
00295             SUIT_OverrideCursor();
00296             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00297               QString matProp;
00298               matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString();
00299               Material_Model material;
00300               material.fromProperties( matProp );
00301               if ( !material.isPhysical() ) {
00302                 aView->SetColor( It.Value(), c );
00303                 appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
00304               }
00305               // store color to GEOM_Object
00306               _PTR(Study) aStudy = appStudy->studyDS();
00307               _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
00308               GEOM::GEOM_Object_var anObject =
00309               GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
00310               SALOMEDS::Color aSColor;
00311               aSColor.R = (double)c.red() / 255.0;
00312               aSColor.G = (double)c.green() / 255.0;
00313               aSColor.B = (double)c.blue() / 255.0;
00314               anObject->SetColor( aSColor );
00315               anObject->SetAutoColor( false );           
00316             }
00317             GeometryGUI::Modified();
00318           }
00319         } // if ( isVTK )
00320         else if ( isOCC ) {
00321                Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
00322           if ( !io.IsNull() ) {
00323             Quantity_Color aColor;
00324             io->Color( aColor ); 
00325             QColor ic = QColor((int )( aColor.Red() * 255.0 ),
00326                            (int)( aColor.Green() * 255.0 ),
00327                            (int)( aColor.Blue() * 255.0 ));        
00328 
00329                            QVariant v = appStudy->getObjectProperty(mgrId,selected.First()->getEntry(), COLOR_PROP, ic);
00330 
00331             QColor initcolor = v.value<QColor>();
00332             QColor c =  QColorDialog::getColor( initcolor, app->desktop() );
00333             if ( c.isValid() ) {
00334               SUIT_OverrideCursor();
00335               aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
00336               OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
00337               Handle (AIS_InteractiveContext) ic = vm->getAISContext();
00338               for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00339                 QString matProp;
00340                 matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString();
00341               Material_Model material;
00342               material.fromProperties( matProp );
00343                 io = GEOMBase::GetAIS( It.Value(), true );
00344                 if ( !io.IsNull()  && !material.isPhysical() ) { // change color only for shapes with not physical type of material
00345                   
00346                   if ( io->IsKind( STANDARD_TYPE(AIS_Shape) ) ) {
00347                     TopoDS_Shape theShape = Handle(AIS_Shape)::DownCast( io )->Shape();
00348                     bool onlyVertex = (theShape.ShapeType() == TopAbs_VERTEX || GEOM_Displayer::isCompoundOfVertices( theShape ));
00349                     if (onlyVertex) {
00350                       // Set color for a point
00351 
00352                       Handle(AIS_Drawer) aCurDrawer = io->Attributes();
00353                       Handle(Prs3d_PointAspect) aCurPointAspect =  aCurDrawer->PointAspect();
00354                       Quantity_Color aCurColor;
00355                       Standard_Real aCurScale;
00356                       Aspect_TypeOfMarker aCurTypeOfMarker;
00357                       aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
00358                       if ( aCurTypeOfMarker != Aspect_TOM_USERDEFINED ) {
00359                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aCurTypeOfMarker, aColor, aCurScale));
00360                       }
00361                       else {
00362                         Standard_Integer aWidth, aHeight;
00363                         aCurPointAspect->GetTextureSize( aWidth, aHeight );
00364 
00365 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
00366                         Handle(TColStd_HArray1OfByte) aTexture = aCurPointAspect->GetTexture();
00367 #else
00368                         Handle(Graphic3d_HArray1OfBytes) aTexture = aCurPointAspect->GetTexture();
00369 #endif
00370 
00371                         aCurDrawer->SetPointAspect(new Prs3d_PointAspect(aColor, 1, aWidth, aHeight, aTexture));
00372                       }
00373                       ic->SetLocalAttributes(io, aCurDrawer, Standard_False);
00374                     }
00375                   }
00376 
00377                   io->SetColor( aColor );
00378                   if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) ) {
00379                     Handle(GEOM_AISShape) aGAISShape = Handle(GEOM_AISShape)::DownCast( io );
00380                     aGAISShape->SetShadingColor( aColor );
00381                     aGAISShape->storeBoundaryColors();
00382                   }
00383 
00384                   appStudy->setObjectProperty(mgrId,It.Value()->getEntry(), COLOR_PROP, c);
00385                 
00386                   io->Redisplay( Standard_True );
00387 
00388                   // store color to GEOM_Object
00389                   _PTR(Study) aStudy = appStudy->studyDS();
00390                   _PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
00391                   GEOM::GEOM_Object_var anObject =
00392                     GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
00393 
00394 
00395                   SALOMEDS::Color aSColor;
00396                   aSColor.R = (double)c.red() / 255.0;
00397                   aSColor.G = (double)c.green() / 255.0;
00398                   aSColor.B = (double)c.blue() / 255.0;
00399                   anObject->SetColor( aSColor );
00400                   anObject->SetAutoColor( false );              
00401                 }
00402               } // for
00403               ic->UpdateCurrentViewer();
00404               GeometryGUI::Modified();
00405             } // if c.isValid()
00406           } // first IO is not null
00407         } // if ( isOCC )
00408       } // if ( selection not empty )
00409     }
00410   }
00411 
00412   app->updateActions(); //SRN: To update a Save button in the toolbar
00413 }
00414 
00415 void GEOMToolsGUI::OnTexture()
00416 {
00417   SALOME_ListIO selected;
00418   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00419   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00420   if ( app && appStudy ) {
00421     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00422     if ( aSelMgr ) {
00423       aSelMgr->selectedObjects( selected );
00424       if ( !selected.IsEmpty() ) {
00425         SUIT_ViewWindow* window = app->desktop()->activeWindow();
00426         bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
00427         if ( isOCC ) {
00428           QString aTexture = QFileDialog::getOpenFileName(window,tr( "GEOM_SELECT_IMAGE"),QString(), tr("OCC_TEXTURE_FILES"));
00429           if( !aTexture.isEmpty() )
00430           {
00431             SUIT_OverrideCursor();
00432             OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
00433             Handle (AIS_InteractiveContext) ic = vm->getAISContext();
00434             Handle(AIS_InteractiveObject) io ;
00435             for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00436               io = GEOMBase::GetAIS( It.Value(), true );
00437               if ( !io.IsNull() ) {
00438                 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
00439                   Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str()));
00440                 io->Redisplay( Standard_True );
00441               } // if ( !io.IsNull() )
00442             } // for
00443             ic->UpdateCurrentViewer();
00444             GeometryGUI::Modified();
00445             GeometryGUI* myGeomGUI = getGeometryGUI();
00446             myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
00447           } // if ( !selFile.isEmpty() )
00448         } // if ( isOCC )
00449       } // if ( selection not empty )
00450     }
00451   }
00452 
00453   app->updateActions(); //SRN: To update a Save button in the toolbar
00454 }
00455 
00456 void GEOMToolsGUI::OnTransparency()
00457 {
00458   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
00459   dlg.exec();
00460 }
00461 
00462 void GEOMToolsGUI::OnChangeTransparency( bool increase )
00463 {
00464  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00465   if ( !app )
00466     return;
00467   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00468   if ( !aSelMgr )
00469     return;
00470   SALOME_ListIO selected;
00471   aSelMgr->selectedObjects( selected );
00472   if ( selected.IsEmpty() )
00473     return;
00474 
00475   Handle(SALOME_InteractiveObject) FirstIOS =  selected.First();
00476   if ( FirstIOS.IsNull() )
00477     return;
00478 
00479   // Delta
00480   float delta = 0.1; // VSR: 23/11/2010 (transparency value <= 0.05 is ignored)
00481   if ( !increase )
00482     delta *= -1;
00483         
00484   SUIT_ViewWindow* window = app->desktop()->activeWindow();
00485   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
00486   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
00487 
00488   if ( isVTK ) {
00489     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
00490     if ( !vtkVW )
00491       return;
00492     SVTK_View* aView = vtkVW->getView();
00493    
00494     float transp = aView->GetTransparency(FirstIOS);
00495     
00496     // Compute new transparency value
00497     transp = transp + delta;
00498     if ( transp < 0 )
00499       transp = 0;
00500     else if ( transp > 1 )
00501       transp = 1;
00502 
00503     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00504       aView->SetTransparency( It.Value(), transp );
00505     }
00506     aView->Repaint();
00507     GeometryGUI::Modified();
00508   } // if ( isVTK )
00509         
00510   else if ( isOCC ) {
00511     GEOMBase* gb = new GEOMBase();
00512     Handle(GEOM_AISShape) aisShape;
00513    
00514     aisShape = gb->ConvertIOinGEOMAISShape( FirstIOS, true );
00515     if( aisShape.IsNull() )
00516       return;
00517     float transp = aisShape->Transparency();
00518 
00519     // Compute new transparency value
00520     transp = transp + delta;
00521     if ( transp < 0 )
00522       transp = 0;
00523     else if ( transp > 1 )
00524       transp = 1;
00525 
00526     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
00527     if ( !vm )
00528       return;
00529     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
00530     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00531       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
00532       if ( !aisShape.IsNull() ) {
00533         ic->SetTransparency( aisShape, transp, false );
00534         ic->Redisplay( aisShape, Standard_False, Standard_True );
00535       }
00536     } // for...
00537     ic->UpdateCurrentViewer();
00538     GeometryGUI::Modified();
00539   } // if ( isOCC )
00540 }
00541 
00542 void GEOMToolsGUI::OnNbIsos( ActionType actionType )
00543 {
00544   SalomeApp_Application* app =
00545     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00546   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00547   SUIT_ViewWindow* window = app->desktop()->activeWindow();
00548 
00549   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
00550   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
00551 
00552   if(isOCC){ // if is OCCViewer
00553 
00554     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
00555     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
00556 
00557     ic->InitCurrent();
00558     if ( ic->MoreCurrent() ) {
00559       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
00560       CurObject->restoreIsoNumbers();
00561       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
00562 
00563       int UIso = CurDrawer->UIsoAspect()->Number();
00564       int VIso = CurDrawer->VIsoAspect()->Number();
00565 
00566       int newNbUIso = -1;
00567       int newNbVIso = -1;
00568 
00569       if ( actionType == SHOWDLG ) {
00570         GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
00571           new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
00572 
00573         NbIsosDlg->setU( UIso );
00574         NbIsosDlg->setV( VIso );
00575 
00576         if ( NbIsosDlg->exec() ) {
00577           SUIT_OverrideCursor();
00578           
00579           newNbUIso = NbIsosDlg->getU();
00580           newNbVIso = NbIsosDlg->getV();
00581         } else //Cancel case
00582           return;
00583       }
00584       else if ( actionType == INCR || actionType == DECR ) {
00585         int delta = 1;
00586         if (actionType == DECR)
00587           delta = -1;
00588         
00589         newNbUIso = UIso + delta;
00590         newNbVIso = VIso + delta;
00591 
00592         if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
00593           return;
00594       }
00595 
00596       for(; ic->MoreCurrent(); ic->NextCurrent()) {
00597         int aMgrId = window->getViewManager()->getGlobalId();
00598         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
00599 
00600         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
00601 
00602        QVariant v = aStudy->getObjectProperty( aMgrId, CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP , QVariant() );
00603 
00604        int width = v.isValid() ? v.toInt() : 1;
00605 
00606         CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbUIso) );
00607         CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, width , newNbVIso) );
00608 
00609        CurObject->storeIsoNumbers();
00610         
00611         ic->SetLocalAttributes(CurObject, CurDrawer);
00612         ic->Redisplay(CurObject);
00613 
00614         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
00615         aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_PROP, anIsos);
00616       }
00617     }
00618     GeometryGUI::Modified();
00619   }
00620   else if(isVTK){ // if is VTKViewer
00621     //
00622     // Warning. It's works incorrect. must be recheked.
00623     //
00624     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
00625       ( SUIT_Session::session()->activeApplication() );
00626     if ( !app )
00627       return;
00628     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00629     if ( !aSelMgr )
00630       return;
00631     SALOME_ListIO selected;
00632     aSelMgr->selectedObjects( selected );
00633     if ( selected.IsEmpty() )
00634       return;
00635 
00636     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
00637     if ( !vtkVW )
00638       return;
00639 
00640     SALOME_View* view = GEOM_Displayer::GetActiveView();
00641 
00642     vtkActorCollection* aCollection = vtkActorCollection::New();
00643 
00644     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00645       Handle(SALOME_InteractiveObject) anIObject = It.Value();
00646       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
00647       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
00648       if ( vtkPrs ) {
00649         vtkActorCollection* anActors = vtkPrs->GetObjects();
00650         anActors->InitTraversal();
00651         vtkActor* anAct = anActors->GetNextActor();
00652         aCollection->AddItem(anAct);
00653       }
00654     }
00655 
00656     if(aCollection)
00657       aCollection->InitTraversal();
00658     else
00659       return;
00660 
00661     int UIso = 0;
00662     int VIso = 0;
00663 
00664     vtkActor* anAct = aCollection->GetNextActor();
00665     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
00666       anActor->RestoreIsoNumbers();
00667       anActor->GetNbIsos(UIso,VIso);
00668     }
00669     else
00670       return;
00671     
00672     int newNbUIso = -1;
00673     int newNbVIso = -1;
00674 
00675     if ( actionType == SHOWDLG ) {
00676       GEOMToolsGUI_NbIsosDlg* NbIsosDlg =
00677         new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
00678 
00679       NbIsosDlg->setU( UIso );
00680       NbIsosDlg->setV( VIso );
00681 
00682       if ( NbIsosDlg->exec() ) {
00683         SUIT_OverrideCursor();
00684 
00685         newNbUIso = NbIsosDlg->getU();
00686         newNbVIso = NbIsosDlg->getV();
00687       } else 
00688         return; //Cancel case 
00689     }
00690     else if ( actionType == INCR || actionType == DECR ) {
00691       int delta = 1;
00692       if (actionType == DECR)
00693         delta = -1;
00694       
00695       newNbUIso = UIso + delta;
00696       newNbVIso = VIso + delta;
00697       
00698       if ( newNbUIso < 0 || newNbVIso < 0 || newNbUIso > 99 || newNbVIso > 99 )
00699         return;
00700     } 
00701     
00702     while( anAct!=NULL ) {
00703       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)){
00704         // There are no casting to needed actor.
00705         int aIsos[2]={newNbUIso,newNbVIso};
00706         anActor->SetNbIsos(aIsos);
00707        anActor->StoreIsoNumbers();
00708 
00709         QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
00710         int aMgrId = window->getViewManager()->getGlobalId();
00711         aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
00712       }
00713       anAct = aCollection->GetNextActor();
00714     }
00715     view->Repaint();
00716     GeometryGUI::Modified();
00717   } // end vtkviewer
00718 }
00719 
00720 void GEOMToolsGUI::OnDeflection()
00721 {
00722   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
00723   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
00724 
00725 
00726   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
00727   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
00728   int mgrId = window->getViewManager()->getGlobalId();
00729 
00730   if (isOCC) { // if is OCCViewer
00731     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
00732     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
00733 
00734     ic->InitCurrent();
00735     if (ic->MoreCurrent()) {
00736       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
00737 
00738       Standard_Real aDC, aPrevDC;
00739       Standard_Boolean isOwnDC = CurObject->OwnDeviationCoefficient(aDC, aPrevDC);
00740       if (!isOwnDC)
00741         aDC = ic->DeviationCoefficient();
00742 
00743       GEOMToolsGUI_DeflectionDlg * DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
00744         (SUIT_Session::session()->activeApplication()->desktop());
00745       DeflectionDlg->setTheDC(aDC);
00746       double aNewDC = 0.0;
00747       bool ok = false;
00748       while (!ok) {
00749         if (DeflectionDlg->exec()) {
00750           SUIT_OverrideCursor();
00751           aNewDC = DeflectionDlg->getTheDC();
00752           ok = (1e-07 <= aNewDC && aNewDC <= 1.0); // spinbox can return zero
00753           if (ok) {
00754             for (; ic->MoreCurrent(); ic->NextCurrent()) {
00755               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
00756               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
00757               ic->Redisplay(CurObject);
00758               appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
00759             }
00760           }
00761         }
00762         else {
00763           ok = true;
00764         }
00765       }
00766     }
00767     GeometryGUI::Modified();
00768   }
00769   else if (isVTK) { // if is VTKViewer
00770     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
00771       (SUIT_Session::session()->activeApplication());
00772     if (!app)
00773       return;
00774 
00775     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00776     if (!aSelMgr)
00777       return;
00778 
00779     SALOME_ListIO selected;
00780     aSelMgr->selectedObjects(selected);
00781     if (selected.IsEmpty())
00782       return;
00783 
00784     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
00785     if (!vtkVW)
00786       return;
00787 
00788     SALOME_View* view = GEOM_Displayer::GetActiveView();
00789 
00790     vtkActorCollection* aCollection = vtkActorCollection::New();
00791 
00792     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
00793       Handle(SALOME_InteractiveObject) anIObject = It.Value();
00794       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
00795       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
00796       if (vtkPrs) {
00797         vtkActorCollection* anActors = vtkPrs->GetObjects();
00798         anActors->InitTraversal();
00799         vtkActor* anAct = anActors->GetNextActor();
00800         aCollection->AddItem(anAct);
00801       }
00802     }
00803 
00804     if (aCollection)
00805       aCollection->InitTraversal();
00806     else
00807       return;
00808 
00809     double aDC = 0.;
00810 
00811     vtkActor* anAct = aCollection->GetNextActor();
00812     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
00813       aDC = anActor->GetDeflection();
00814     else
00815       return;
00816 
00817     GEOMToolsGUI_DeflectionDlg* DeflectionDlg = new GEOMToolsGUI_DeflectionDlg
00818       (SUIT_Session::session()->activeApplication()->desktop());
00819     DeflectionDlg->setTheDC(aDC);
00820     if (DeflectionDlg->exec()) {
00821       SUIT_OverrideCursor();
00822       aDC = DeflectionDlg->getTheDC();
00823       while (anAct != NULL) {
00824         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
00825           // There are no casting to needed actor.
00826           anActor->SetDeflection(aDC);
00827           appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
00828         }
00829         anAct = aCollection->GetNextActor();
00830       }
00831     }
00832     GeometryGUI::Modified();
00833   } // end vtkviewer
00834 }
00835 
00836 void GEOMToolsGUI::OnSelectOnly(int mode)
00837 {
00838   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00839   if ( app ) {
00840     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00841     GEOM_Displayer aDisp (appStudy);
00842     aDisp.GlobalSelection(mode);
00843     getGeometryGUI()->setLocalSelectionMode(mode);
00844   }
00845 }
00846 
00847 void GEOMToolsGUI::OnShowHideChildren( bool show )
00848 {
00849   SALOME_ListIO selected;
00850   SalomeApp_Application* app =
00851     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00852   
00853   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
00854   
00855   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
00856 
00857   if ( app && disp ) {
00858     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00859     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00860     if ( aSelMgr && appStudy ) {
00861       aSelMgr->selectedObjects( selected );
00862       if ( !selected.IsEmpty() ) {
00863         _PTR(Study) aStudy = appStudy->studyDS();
00864         _PTR(StudyBuilder) B = aStudy->NewBuilder();
00865 
00866         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
00867         if ( aLocked ) {
00868           SUIT_MessageBox::warning( app->desktop(),
00869                                     QObject::tr( "WRN_WARNING" ),
00870                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
00871           return;
00872         }
00873 
00874         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00875           Handle(SALOME_InteractiveObject) IObject = It.Value();
00876 
00877           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
00878           _PTR(GenericAttribute) anAttr;
00879           if ( obj ) {
00880             _PTR(AttributeExpandable) aExp = B->FindOrCreateAttribute( obj, "AttributeExpandable" );
00881             aExp->SetExpandable( show );
00882             if(!show)
00883               disp->EraseWithChildren(IObject,true);
00884           } // if ( obj )
00885         } // iterator
00886       }
00887     }
00888     app->updateObjectBrowser( false );
00889     app->updateActions();
00890   }
00891 }
00892 
00893 void GEOMToolsGUI::OnPointMarker()
00894 {
00895   GEOMToolsGUI_MarkerDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
00896   dlg.exec();
00897 }
00898 
00899 void GEOMToolsGUI::OnMaterialProperties()
00900 {
00901   GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
00902   dlg.exec();
00903 }
00904 
00905 void GEOMToolsGUI::OnUnpublishObject() {
00906   SALOME_ListIO selected;
00907   SalomeApp_Application* app =
00908     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00909 
00910   SalomeApp_Module* mod = app ? dynamic_cast<SalomeApp_Module*>(app->activeModule()) : 0;
00911 
00912   GEOM_Displayer* disp  = mod ? dynamic_cast<GEOM_Displayer*>(mod->displayer()) : 0;
00913   
00914   if ( app && disp ) {
00915     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
00916     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00917     if ( aSelMgr && appStudy ) {
00918       aSelMgr->selectedObjects( selected );
00919       if ( !selected.IsEmpty() ) {
00920         _PTR(Study) aStudy = appStudy->studyDS();
00921         _PTR(StudyBuilder) B = aStudy->NewBuilder();
00922 
00923         bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
00924         if ( aLocked ) {
00925           SUIT_MessageBox::warning( app->desktop(),
00926                                     QObject::tr( "WRN_WARNING" ),
00927                                     QObject::tr( "WRN_STUDY_LOCKED" ) );
00928           return;
00929         }
00930 
00931         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
00932           Handle(SALOME_InteractiveObject) IObject = It.Value();
00933 
00934           _PTR(SObject) obj ( aStudy->FindObjectID( IObject->getEntry() ) );
00935           _PTR(GenericAttribute) anAttr;
00936           if ( obj ) {
00937             _PTR(AttributeDrawable) aDrw = B->FindOrCreateAttribute( obj, "AttributeDrawable" );
00938             aDrw->SetDrawable( false );
00939             disp->EraseWithChildren(IObject);
00940           } // if ( obj )
00941         } // iterator
00942         aSelMgr->clearSelected();
00943       }
00944     }
00945     app->updateObjectBrowser( false );
00946     app->updateActions();
00947   }
00948  
00949 }
00950 
00951 void GEOMToolsGUI::OnPublishObject() {
00952   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00953   if(!app)
00954     return;
00955 
00956   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00957   if(!appStudy)
00958     return;
00959   
00960   _PTR(Study) aStudy = appStudy->studyDS();
00961   
00962   if(!aStudy)
00963     return;
00964 
00965   //Check lock of the study
00966   bool aLocked = ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() ) )->IsLocked();
00967   if ( aLocked ) {
00968     SUIT_MessageBox::warning( app->desktop(),
00969                               QObject::tr( "WRN_WARNING" ),
00970                               QObject::tr( "WRN_STUDY_LOCKED" ) );
00971     return;
00972   } 
00973   
00974   GEOMToolsGUI_PublishDlg * publishDlg =
00975     new GEOMToolsGUI_PublishDlg( SUIT_Session::session()->activeApplication()->desktop() );
00976   publishDlg->exec();
00977 }
00978 
00979 
00980 void GEOMToolsGUI::OnEdgeWidth()
00981 {
00982   SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
00983   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
00984 
00985 
00986   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
00987   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
00988   int mgrId = window->getViewManager()->getGlobalId();
00989 
00990   if (isOCC) { // if is OCCViewer
00991     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
00992     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
00993     ic->InitCurrent();
00994     if (ic->MoreCurrent()) {
00995       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
00996 
00997       int aWidth = (int)CurObject->Width();
00998 
00999       GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
01000         (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
01001       Dlg->setTheLW(aWidth);
01002       int aNewWidth = 0;
01003       if (Dlg->exec()) {
01004        aNewWidth = Dlg->getTheLW();
01005        bool ok = (aNewWidth != aWidth && aNewWidth != 0 );
01006        if (ok) {
01007          for(; ic->MoreCurrent(); ic->NextCurrent()) {
01008            CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
01009            CurObject->SetWidth(aNewWidth);
01010            ic->Redisplay(CurObject);
01011            appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP, aNewWidth);
01012          }
01013        }
01014       }
01015     }
01016     else {
01017       return;
01018     }
01019     GeometryGUI::Modified();
01020   }
01021   else if (isVTK) { // if is VTKViewer
01022     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
01023       (SUIT_Session::session()->activeApplication());
01024     if (!app)
01025       return;
01026 
01027     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
01028     if (!aSelMgr)
01029       return;
01030 
01031     SALOME_ListIO selected;
01032     aSelMgr->selectedObjects(selected);
01033     if (selected.IsEmpty())
01034       return;
01035 
01036     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>(window);
01037     if (!vtkVW)
01038       return;
01039 
01040     SALOME_View* view = GEOM_Displayer::GetActiveView();
01041 
01042     vtkActorCollection* aCollection = vtkActorCollection::New();
01043 
01044     for (SALOME_ListIteratorOfListIO It (selected); It.More(); It.Next()) {
01045       Handle(SALOME_InteractiveObject) anIObject = It.Value();
01046       SALOME_Prs* aPrs = view->CreatePrs(anIObject->getEntry());
01047       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>(aPrs);
01048       if (vtkPrs) {
01049         vtkActorCollection* anActors = vtkPrs->GetObjects();
01050         anActors->InitTraversal();
01051         vtkActor* anAct = anActors->GetNextActor();
01052         aCollection->AddItem(anAct);
01053       }
01054     }
01055 
01056     if (aCollection)
01057       aCollection->InitTraversal();
01058     else
01059       return;
01060 
01061     int aWidth = 1;
01062 
01063     vtkActor* anAct = aCollection->GetNextActor();
01064     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct))
01065       aWidth = anActor->GetWidth();
01066     else
01067       return;
01068 
01069     GEOMToolsGUI_LineWidthDlg * Dlg = new GEOMToolsGUI_LineWidthDlg
01070       (SUIT_Session::session()->activeApplication()->desktop(),"EDGE_WIDTH_TLT");
01071     
01072     Dlg->setTheLW(aWidth);
01073     if (Dlg->exec()) {
01074       SUIT_OverrideCursor();
01075       aWidth = Dlg->getTheLW();
01076       while (anAct != NULL) {
01077         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
01078           // There are no casting to needed actor.
01079           anActor->SetWidth(aWidth);
01080           appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), EDGE_WIDTH_PROP, aWidth);
01081         }
01082         anAct = aCollection->GetNextActor();
01083       }
01084     }
01085     GeometryGUI::Modified();
01086   } // end vtkviewer
01087 }
01088 
01089 
01090 void GEOMToolsGUI::OnIsosWidth() {
01091   SalomeApp_Application* app =
01092     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
01093   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
01094   SUIT_ViewWindow* window = app->desktop()->activeWindow();
01095 
01096   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
01097   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
01098 
01099   if(isOCC){ // if is OCCViewer
01100 
01101     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
01102     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
01103 
01104     ic->InitCurrent();
01105     if ( ic->MoreCurrent() ) {
01106       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
01107       CurObject->restoreIsoNumbers();
01108       Handle(AIS_Drawer)    CurDrawer = CurObject->Attributes();
01109 
01110       Handle(Graphic3d_AspectLine3d) asp = CurDrawer->UIsoAspect()->Aspect();
01111       
01112       Quantity_Color C;
01113       Aspect_TypeOfLine T;
01114       Standard_Real W;
01115       asp->Values(C,T,W);
01116 
01117       int aWidth = (int)W;
01118 
01119       GEOMToolsGUI_LineWidthDlg * Dlg =
01120        new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(),"ISOS_WIDTH_TLT" );
01121 
01122       Dlg->setTheLW( aWidth );
01123 
01124       if ( Dlg->exec() ) {
01125        SUIT_OverrideCursor();          
01126        aWidth = Dlg->getTheLW();
01127       } else //Cancel case
01128        return;
01129       
01130       for(; ic->MoreCurrent(); ic->NextCurrent()) {
01131        int aMgrId = window->getViewManager()->getGlobalId();
01132        CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
01133        
01134        Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
01135        
01136        CurObject->Attributes()->UIsoAspect()->SetWidth(aWidth);
01137        CurObject->Attributes()->VIsoAspect()->SetWidth(aWidth);
01138        
01139        ic->Redisplay(CurObject);
01140        
01141        aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
01142       }
01143       GeometryGUI::Modified();
01144     }
01145   }
01146   else if(isVTK){ // if is VTKViewer
01147     //
01148     // Warning. It's works incorrect. must be recheked.
01149     //
01150     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >
01151       ( SUIT_Session::session()->activeApplication() );
01152     if ( !app )
01153       return;
01154     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
01155     if ( !aSelMgr )
01156       return;
01157     SALOME_ListIO selected;
01158     aSelMgr->selectedObjects( selected );
01159     if ( selected.IsEmpty() )
01160       return;
01161 
01162     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
01163     if ( !vtkVW )
01164       return;
01165 
01166     SALOME_View* view = GEOM_Displayer::GetActiveView();
01167 
01168     vtkActorCollection* aCollection = vtkActorCollection::New();
01169 
01170     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
01171       Handle(SALOME_InteractiveObject) anIObject = It.Value();
01172       SALOME_Prs* aPrs = view->CreatePrs( anIObject->getEntry() );
01173       SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( aPrs );
01174       if ( vtkPrs ) {
01175         vtkActorCollection* anActors = vtkPrs->GetObjects();
01176         anActors->InitTraversal();
01177         vtkActor* anAct = anActors->GetNextActor();
01178         aCollection->AddItem(anAct);
01179       }
01180     }
01181 
01182     if(aCollection)
01183       aCollection->InitTraversal();
01184     else
01185       return;
01186 
01187     int aWidth = 1;
01188 
01189     vtkActor* anAct = aCollection->GetNextActor();
01190     if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
01191       aWidth = anActor->GetIsosWidth();
01192     }
01193     else
01194       return;
01195     
01196     GEOMToolsGUI_LineWidthDlg* Dlg =
01197       new GEOMToolsGUI_LineWidthDlg( SUIT_Session::session()->activeApplication()->desktop(), "ISOS_WIDTH_TLT" );
01198     
01199     Dlg->setTheLW( aWidth );
01200     if (Dlg->exec() ) {
01201       SUIT_OverrideCursor();
01202       aWidth = Dlg->getTheLW();
01203     } else 
01204       return; //Cancel case 
01205     
01206     while( anAct!= NULL ) {
01207       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
01208         // There are no casting to needed actor.
01209        anActor->SetIsosWidth(aWidth);
01210        int aMgrId = window->getViewManager()->getGlobalId();
01211         aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
01212       }
01213       anAct = aCollection->GetNextActor();
01214     }
01215     
01216     view->Repaint();
01217     GeometryGUI::Modified();
01218   } // end vtkviewer  
01219 }
01220 
01221 void GEOMToolsGUI::OnBringToFront() {
01222  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
01223   if ( !app )
01224     return;
01225 
01226   SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
01227   if(!mod)
01228     return;
01229   
01230   GEOM_Displayer* disp  = dynamic_cast<GEOM_Displayer*>(mod->displayer());
01231   
01232   if(!disp)
01233     return;
01234   
01235   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
01236   if ( !aSelMgr )
01237     return;
01238 
01239   SALOME_ListIO selected;
01240   aSelMgr->selectedObjects( selected );
01241   if ( selected.IsEmpty() )
01242     return;
01243 
01244   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());  
01245   if(!appStudy)
01246     return;
01247 
01248   SUIT_ViewWindow* window = app->desktop()->activeWindow();
01249 
01250   OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
01251   if ( !vm )
01252     return;
01253   
01254   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
01255 
01256   QAction* a = getGeometryGUI()->getAction( GEOMOp::OpBringToFront );
01257   bool checked = a->isChecked();
01258   
01259   if ( isOCC ) {
01260     GEOMBase* gb = new GEOMBase();
01261     Handle(GEOM_AISShape) aisShape;
01262    
01263     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
01264     SALOME_ListIO anIOlst;
01265     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
01266       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
01267       if ( !aisShape.IsNull() ) {
01268        aisShape->setTopLevel(checked);
01269        int aMgrId = window->getViewManager()->getGlobalId();
01270        appStudy->setObjectProperty( aMgrId, aisShape->getIO()->getEntry(), TOP_LEVEL_PROP, checked );
01271        anIOlst.Append(aisShape->getIO());
01272       }
01273     } // for...
01274     disp->Redisplay(anIOlst);
01275     GeometryGUI::Modified();
01276   } // if ( isOCC )
01277 }
01278 
01279 void GEOMToolsGUI::OnClsBringToFront() {
01280   SalomeApp_Application* app =
01281     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
01282   if(!app)
01283     return;
01284 
01285   SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
01286   if(!mod)
01287     return;
01288   
01289   GEOM_Displayer* disp  = dynamic_cast<GEOM_Displayer*>(mod->displayer());
01290   
01291   if(!disp)
01292     return;
01293 
01294 
01295   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());  
01296   if(!appStudy)
01297     return;
01298   
01299   SUIT_ViewWindow* window = app->desktop()->activeWindow();  
01300   
01301   bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
01302   
01303   if(isOCC){ // if is OCCViewer
01304     
01305     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
01306     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
01307     
01308     SALOME_ListIO anIOlst;
01309     AIS_ListOfInteractive aList;
01310     ic->DisplayedObjects( aList );
01311     for ( AIS_ListIteratorOfListOfInteractive it( aList ); it.More(); it.Next() ) {
01312       
01313       Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(it.Value());
01314       
01315       if(CurObject.IsNull())
01316        continue;
01317       
01318       CurObject->setTopLevel(Standard_False);
01319       
01320       int aMgrId = window->getViewManager()->getGlobalId();
01321       appStudy->setObjectProperty( aMgrId, QString(CurObject->getIO()->getEntry()), TOP_LEVEL_PROP, Standard_False );
01322       anIOlst.Append(CurObject->getIO());
01323     }
01324     disp->Redisplay(anIOlst);
01325     GeometryGUI::Modified();
01326   }
01327 }
01328