]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI.cxx
Salome HOME
29b73920917965e8505f65c1acb1dad263540233
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : GeometryGUI.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25
26 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
27 #include "Python.h"
28 #include "GeometryGUI.h"
29 #include "GeometryGUI_Operations.h"
30 #include "GEOMGUI_OCCSelector.h"
31 #include "GEOMGUI_Selection.h"
32 #include "GEOM_Displayer.h"
33 #include "GEOM_AISShape.hxx"
34
35 #include "GEOM_Actor.h"
36
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_ViewManager.h>
42
43 #include <OCCViewer_ViewWindow.h>
44 #include <OCCViewer_ViewPort3d.h>
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewManager.h>
47
48 #include <SOCC_ViewModel.h>
49 #include <SOCC_ViewWindow.h>
50
51 #include <SVTK_ViewWindow.h>
52 #include <SVTK_RenderWindowInteractor.h>
53 #include <SVTK_InteractorStyle.h>
54 #include <SVTK_ViewModel.h>
55
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58
59 #include <LightApp_SelectionMgr.h>
60 #include <LightApp_VTKSelector.h>
61 #include <LightApp_DataObject.h>
62 #include <LightApp_Preferences.h>
63
64 #include <SALOME_LifeCycleCORBA.hxx>
65 #include <SALOME_ListIO.hxx>
66 #include <SALOME_ListIteratorOfListIO.hxx>
67
68 #include <SALOMEDSClient_ClientFactory.hxx>
69 #include <SALOMEDSClient_IParameters.hxx>
70
71 // External includes
72 #include <QMenu>
73 #include <QAction>
74 #include <QFileInfo>
75 #include <QString>
76 #include <QPainter>
77
78 #include <AIS_Drawer.hxx>
79 #include <AIS_ListOfInteractive.hxx>
80 #include <AIS_ListIteratorOfListOfInteractive.hxx>
81 #include <Prs3d_Drawer.hxx>
82 #include <Prs3d_IsoAspect.hxx>
83 #include <Aspect_TypeOfMarker.hxx>
84 #include <OSD_SharedLibrary.hxx>
85 #include <NCollection_DataMap.hxx>
86 #include <Graphic3d_HArray1OfBytes.hxx>
87
88 #include <utilities.h>
89
90 #include <vtkCamera.h>
91 #include <vtkRenderer.h>
92
93 #include "GEOMImpl_Types.hxx"
94
95 extern "C" {
96   Standard_EXPORT CAM_Module* createModule() {
97     return new GeometryGUI();
98   }
99 }
100
101 GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
102
103 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
104
105 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
106 {
107   // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
108   if (CORBA::is_nil(myComponentGeom))
109     InitGeomGen();
110   return GeometryGUI::myComponentGeom;
111 }
112
113 bool GeometryGUI::InitGeomGen()
114 {
115   GeometryGUI aGG;
116   if( CORBA::is_nil( myComponentGeom ) ) return false;
117   return true;
118 }
119
120 //=======================================================================
121 // function : ClientSObjectToObject
122 // purpose  :
123 //=======================================================================
124 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
125 {
126   _PTR(GenericAttribute) anAttr;
127   CORBA::Object_var anObj;
128   try {
129     std::string aValue = theSObject->GetIOR();
130     if (strcmp(aValue.c_str(), "") != 0) {
131       CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
132       anObj = anORB->string_to_object(aValue.c_str());
133     }
134   } catch(...) {
135     INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
136   }
137   return anObj._retn();
138 }
139
140 //=======================================================================
141 // function : ClientStudyToStudy
142 // purpose  :
143 //=======================================================================
144 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
145 {
146   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
147   CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
148   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
149   int aStudyID = theStudy->StudyId();
150   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
151   return aDSStudy._retn();
152 }
153
154 //=======================================================================
155 // function : GeometryGUI::GeometryGUI()
156 // purpose  : Constructor
157 //=======================================================================
158 GeometryGUI::GeometryGUI() :
159   SalomeApp_Module( "GEOM" ),
160   LightApp_Module( "GEOM" )
161 {
162   if ( CORBA::is_nil( myComponentGeom ) )
163   {
164     Engines::Component_var comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "GEOM" );
165     myComponentGeom  = GEOM::GEOM_Gen::_narrow( comp );
166   }
167
168   myActiveDialogBox = 0;
169
170   gp_Pnt origin = gp_Pnt(0., 0., 0.);
171   gp_Dir direction = gp_Dir(0., 0., 1.);
172   myWorkingPlane = gp_Ax3(origin, direction);
173
174   myDisplayer = 0;
175   myLocalSelectionMode = GEOM_ALLOBJECTS;
176 }
177
178 //=======================================================================
179 // function : GeometryGUI::~GeometryGUI()
180 // purpose  : Destructor
181 //=======================================================================
182 GeometryGUI::~GeometryGUI()
183 {
184   while (!myOCCSelectors.isEmpty())
185     delete myOCCSelectors.takeFirst();
186
187   while (!myVTKSelectors.isEmpty())
188     delete myVTKSelectors.takeFirst();
189
190   qDeleteAll(myGUIMap);
191 }
192
193 //=======================================================================
194 // function : GeometryGUI::getLibrary()
195 // purpose  : get or load GUI library by name [ internal ]
196 //=======================================================================
197 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
198 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
199 {
200   if ( !myGUIMap.contains( libraryName ) ) {
201     // try to load library if it is not loaded yet
202 #ifndef WNT
203     QString dirs = getenv( "LD_LIBRARY_PATH" );
204     QString sep  = ":";
205 #else
206     QString dirs = getenv( "PATH" );
207     QString sep  = ";";
208 #endif
209     if ( !dirs.isEmpty() ) {
210       QStringList dirList = dirs.split(sep, QString::SkipEmptyParts ); // skip empty entries
211       QListIterator<QString> it( dirList ); it.toBack();
212       while ( it.hasPrevious() ) {
213         QFileInfo fi( Qtx::addSlash( it.previous() ) + libraryName );
214         if ( fi.exists() ) {
215           OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().constData() );
216           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
217           if ( !res ) {
218             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
219             continue; // continue search further
220           }
221           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
222           if ( osdF != NULL ) {
223             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
224             GEOMGUI* libGUI = (*func)( this );
225             if ( libGUI ) {
226               myGUIMap[ libraryName ] = libGUI;
227               break; // found and loaded!
228             }
229           }
230         }
231       }
232     }
233   }
234   return myGUIMap.contains( libraryName ) ? myGUIMap[ libraryName ] : 0;
235 }
236
237 //=======================================================================
238 // function : GeometryGUI::ActiveWorkingPlane()
239 // purpose  : Activate Working Plane View
240 //=======================================================================
241 void GeometryGUI::ActiveWorkingPlane()
242 {
243   gp_Dir DZ = myWorkingPlane.Direction();
244   gp_Dir DY = myWorkingPlane.YDirection();
245
246   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
247   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
248   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
249
250   if( ViewOCC ) {
251     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
252     if ( vw ) {
253       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
254
255       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
256       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
257
258       vw->onViewFitAll();
259     }
260   }
261   else if( ViewVTK ) {
262     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
263     if ( vw ) {
264       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
265
266       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
267       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
268       camera->SetFocalPoint(0,0,0);
269
270       vw->onFitAll();
271     }
272   }
273 }
274
275 //=======================================================================
276 // function : GeometryGUI::SetActiveDialogBox()
277 // purpose  : Set active dialog box
278 //=======================================================================
279 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
280 {
281   myActiveDialogBox = (QDialog*)aDlg;
282 }
283
284 //=======================================================================
285 // function : GeometryGUI::EmitSignalDeactivateDialog()
286 // purpose  : Emit a signal to deactivate the active dialog Box
287 //=======================================================================
288 void GeometryGUI::EmitSignalDeactivateDialog()
289 {
290   emit SignalDeactivateActiveDialog();
291 }
292
293 //=======================================================================
294 // function : GeometryGUI::EmitSignalCloseAllDialogs()
295 // purpose  : Emit a signal to close all non modal dialogs box
296 //=======================================================================
297 void GeometryGUI::EmitSignalCloseAllDialogs()
298 {
299   emit SignalCloseAllDialogs();
300 }
301
302 //=======================================================================
303 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
304 // purpose  : Emit a signal to inform that default real spin box step has
305 //            been changed
306 //=======================================================================
307 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
308 {
309   emit SignalDefaultStepValueChanged(newVal);
310 }
311
312 //=======================================================================
313 // function : GeometryGUI::OnGUIEvent()
314 // purpose  : common slot for all menu/toolbar actions
315 //=======================================================================
316 void GeometryGUI::OnGUIEvent()
317 {
318   const QObject* obj = sender();
319   if ( !obj || !obj->inherits( "QAction" ) )
320     return;
321   int id = actionId((QAction*)obj);
322   if ( id != -1 )
323     OnGUIEvent( id );
324 }
325
326 //=======================================================================
327 // function : GeometryGUI::OnGUIEvent()
328 // purpose  : manage all events on GUI [static]
329 //=======================================================================
330 void GeometryGUI::OnGUIEvent( int id )
331 {
332   SUIT_Application* anApp = application();
333   if (!anApp) return;
334   SUIT_Desktop* desk = anApp->desktop();
335
336   // check type of the active viewframe
337   SUIT_ViewWindow* window = desk->activeWindow();
338   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
339   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
340   // if current viewframe is not of OCC and not of VTK type - return immediately
341   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
342   QList<int> NotViewerDependentCommands;
343   NotViewerDependentCommands << GEOMOp::OpRename
344                              << GEOMOp::OpDelete
345                              << GEOMOp::OpShow
346                              << GEOMOp::OpShowOnly
347                              << GEOMOp::OpShowChildren
348                              << GEOMOp::OpHideChildren
349                              << GEOMOp::OpPointMarker;
350   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
351       return;
352
353   // fix for IPAL9103, point 2
354   if ( CORBA::is_nil( GetGeomGen() ) ) {
355     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
356     return;
357   }
358
359   QString libName;
360   // find corresponding GUI library
361   switch ( id ) {
362   case GEOMOp::OpImport:           // MENU FILE - IMPORT
363   case GEOMOp::OpExport:           // MENU FILE - EXPORT
364   case GEOMOp::OpSelectVertex:     // POPUP MENU - SELECT ONLY - VERTEX
365   case GEOMOp::OpSelectEdge:       // POPUP MENU - SELECT ONLY - EDGE
366   case GEOMOp::OpSelectWire:       // POPUP MENU - SELECT ONLY - WIRE
367   case GEOMOp::OpSelectFace:       // POPUP MENU - SELECT ONLY - FACE
368   case GEOMOp::OpSelectShell:      // POPUP MENU - SELECT ONLY - SHELL
369   case GEOMOp::OpSelectSolid:      // POPUP MENU - SELECT ONLY - SOLID
370   case GEOMOp::OpSelectCompound:   // POPUP MENU - SELECT ONLY - COMPOUND
371   case GEOMOp::OpSelectAll:        // POPUP MENU - SELECT ONLY - SELECT ALL
372   case GEOMOp::OpDelete:           // MENU EDIT - DELETE
373   case GEOMOp::OpCheckGeom:        // MENU TOOLS - CHECK GEOMETRY
374   case GEOMOp::OpDeflection:       // POPUP MENU - DEFLECTION COEFFICIENT
375   case GEOMOp::OpColor:            // POPUP MENU - COLOR
376   case GEOMOp::OpTransparency:     // POPUP MENU - TRANSPARENCY
377   case GEOMOp::OpIsos:             // POPUP MENU - ISOS
378   case GEOMOp::OpAutoColor:        // POPUP MENU - AUTO COLOR
379   case GEOMOp::OpNoAutoColor:      // POPUP MENU - DISABLE AUTO COLOR
380   case GEOMOp::OpShowChildren:     // POPUP MENU - SHOW CHILDREN
381   case GEOMOp::OpHideChildren:     // POPUP MENU - HIDE CHILDREN
382   case GEOMOp::OpPointMarker:      // POPUP MENU - POINT MARKER
383   case GEOMOp::OpRename:           // POPUP MENU - RENAME
384     libName = "GEOMToolsGUI";
385     break;
386   case GEOMOp::OpDisplayMode:      // MENU VIEW - WIREFRAME/SHADING
387   case GEOMOp::OpShowAll:          // MENU VIEW - SHOW ALL
388   case GEOMOp::OpShowOnly:         // MENU VIEW - DISPLAY ONLY
389   case GEOMOp::OpHideAll:          // MENU VIEW - ERASE ALL
390   case GEOMOp::OpHide:             // MENU VIEW - ERASE
391   case GEOMOp::OpShow:             // MENU VIEW - DISPLAY
392   case GEOMOp::OpSwitchVectors:    // MENU VIEW - VECTOR MODE
393   case GEOMOp::OpWireframe:        // POPUP MENU - WIREFRAME
394   case GEOMOp::OpShading:          // POPUP MENU - SHADING
395   case GEOMOp::OpVectors:          // POPUP MENU - VECTORS
396     libName = "DisplayGUI";
397     break;
398   case GEOMOp::OpPoint:            // MENU BASIC - POINT
399   case GEOMOp::OpLine:             // MENU BASIC - LINE
400   case GEOMOp::OpCircle:           // MENU BASIC - CIRCLE
401   case GEOMOp::OpEllipse:          // MENU BASIC - ELLIPSE
402   case GEOMOp::OpArc:              // MENU BASIC - ARC
403   case GEOMOp::OpVector:           // MENU BASIC - VECTOR
404   case GEOMOp::OpPlane:            // MENU BASIC - PLANE
405   case GEOMOp::OpCurve:            // MENU BASIC - CURVE
406   case GEOMOp::OpLCS:              // MENU BASIC - REPAIR
407     libName = "BasicGUI";
408     break;
409   case GEOMOp::OpBox:              // MENU PRIMITIVE - BOX
410   case GEOMOp::OpCylinder:         // MENU PRIMITIVE - CYLINDER
411   case GEOMOp::OpSphere:           // MENU PRIMITIVE - SPHERE
412   case GEOMOp::OpTorus:            // MENU PRIMITIVE - TORUS
413   case GEOMOp::OpCone:             // MENU PRIMITIVE - CONE
414   case GEOMOp::OpRectangle:        // MENU PRIMITIVE - FACE
415   case GEOMOp::OpDisk:             // MENU PRIMITIVE - DISK
416     libName = "PrimitiveGUI";
417     break;
418   case GEOMOp::OpPrism:            // MENU GENERATION - PRISM
419   case GEOMOp::OpRevolution:       // MENU GENERATION - REVOLUTION
420   case GEOMOp::OpFilling:          // MENU GENERATION - FILLING
421   case GEOMOp::OpPipe:             // MENU GENERATION - PIPE
422     libName = "GenerationGUI";
423     break;
424   case GEOMOp::Op2dSketcher:       // MENU ENTITY - SKETCHER
425   case GEOMOp::Op3dSketcher:       // MENU ENTITY - 3D SKETCHER
426   case GEOMOp::OpExplode:          // MENU ENTITY - EXPLODE
427     libName = "EntityGUI";
428     break;
429   case GEOMOp::OpEdge:             // MENU BUILD - EDGE
430   case GEOMOp::OpWire:             // MENU BUILD - WIRE
431   case GEOMOp::OpFace:             // MENU BUILD - FACE
432   case GEOMOp::OpShell:            // MENU BUILD - SHELL
433   case GEOMOp::OpSolid:            // MENU BUILD - SOLID
434   case GEOMOp::OpCompound:         // MENU BUILD - COMPUND
435     libName = "BuildGUI";
436     break;
437   case GEOMOp::OpFuse:             // MENU BOOLEAN - FUSE
438   case GEOMOp::OpCommon:           // MENU BOOLEAN - COMMON
439   case GEOMOp::OpCut:              // MENU BOOLEAN - CUT
440   case GEOMOp::OpSection:          // MENU BOOLEAN - SECTION
441     libName = "BooleanGUI";
442     break;
443   case GEOMOp::OpTranslate:        // MENU TRANSFORMATION - TRANSLATION
444   case GEOMOp::OpRotate:           // MENU TRANSFORMATION - ROTATION
445   case GEOMOp::OpChangeLoc:        // MENU TRANSFORMATION - LOCATION
446   case GEOMOp::OpMirror:           // MENU TRANSFORMATION - MIRROR
447   case GEOMOp::OpScale:            // MENU TRANSFORMATION - SCALE
448   case GEOMOp::OpOffset:           // MENU TRANSFORMATION - OFFSET
449   case GEOMOp::OpMultiTranslate:   // MENU TRANSFORMATION - MULTI-TRANSLATION
450   case GEOMOp::OpMultiRotate:      // MENU TRANSFORMATION - MULTI-ROTATION
451   case GEOMOp::OpReimport:         // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
452     libName = "TransformationGUI";
453     break;
454   case GEOMOp::OpPartition:        // MENU OPERATION - PARTITION
455   case GEOMOp::OpArchimede:        // MENU OPERATION - ARCHIMEDE
456   case GEOMOp::OpFillet3d:         // MENU OPERATION - FILLET
457   case GEOMOp::OpChamfer:          // MENU OPERATION - CHAMFER
458   case GEOMOp::OpClipping:         // MENU OPERATION - CLIPPING RANGE
459   case GEOMOp::OpShapesOnShape:    // MENU OPERATION - GET SHAPES ON SHAPE
460   case GEOMOp::OpFillet2d:         // MENU OPERATION - FILLET 2D
461   case GEOMOp::OpFillet1d:         // MENU OPERATION - FILLET 1D
462   case GEOMOp::OpSharedShapes:     // MENU OPERATION - GET SHARED SHAPES
463     libName = "OperationGUI";
464     break;
465   case GEOMOp::OpSewing:           // MENU REPAIR - SEWING
466   case GEOMOp::OpSuppressFaces:    // MENU REPAIR - SUPPRESS FACES
467   case GEOMOp::OpSuppressHoles:    // MENU REPAIR - SUPPRESS HOLE
468   case GEOMOp::OpShapeProcess:     // MENU REPAIR - SHAPE PROCESSING
469   case GEOMOp::OpCloseContour:     // MENU REPAIR - CLOSE CONTOUR
470   case GEOMOp::OpRemoveIntWires:   // MENU REPAIR - REMOVE INTERNAL WIRES
471   case GEOMOp::OpAddPointOnEdge:   // MENU REPAIR - ADD POINT ON EDGE
472   case GEOMOp::OpFreeBoundaries:   // MENU MEASURE - FREE BOUNDARIES
473   case GEOMOp::OpFreeFaces:        // MENU MEASURE - FREE FACES
474   case GEOMOp::OpOrientation:      // MENU REPAIR - CHANGE ORIENTATION
475   case GEOMOp::OpGlueFaces:        // MENU REPAIR - GLUE FACES
476   case GEOMOp::OpRemoveExtraEdges: // MENU REPAIR - REMOVE EXTRA EDGES
477     libName = "RepairGUI";
478     break;
479   case GEOMOp::OpProperties:       // MENU MEASURE - PROPERTIES
480   case GEOMOp::OpCenterMass:       // MENU MEASURE - CDG
481   case GEOMOp::OpInertia:          // MENU MEASURE - INERTIA
482   case GEOMOp::OpNormale:          // MENU MEASURE - NORMALE
483   case GEOMOp::OpBoundingBox:      // MENU MEASURE - BOUNDING BOX
484   case GEOMOp::OpMinDistance:      // MENU MEASURE - MIN DISTANCE
485   case GEOMOp::OpAngle:            // MENU MEASURE - ANGLE
486   case GEOMOp::OpTolerance:        // MENU MEASURE - TOLERANCE
487   case GEOMOp::OpWhatIs:           // MENU MEASURE - WHATIS
488   case GEOMOp::OpCheckShape:       // MENU MEASURE - CHECK
489   case GEOMOp::OpCheckCompound:    // MENU MEASURE - CHECK COMPOUND OF BLOCKS
490   case GEOMOp::OpPointCoordinates: // MENU MEASURE - POINT COORDINATES
491     libName = "MeasureGUI";
492     break;
493   case GEOMOp::OpGroupCreate:      // MENU GROUP - CREATE
494   case GEOMOp::OpGroupCreatePopup: // POPUP MENU - CREATE GROUP
495   case GEOMOp::OpGroupEdit:        // MENU GROUP - EDIT
496     libName = "GroupGUI";
497     break;
498   case GEOMOp::OpHexaSolid:        // MENU BLOCKS - HEXAHEDRAL SOLID
499   case GEOMOp::OpMultiTransform:   // MENU BLOCKS - MULTI-TRANSFORMATION
500   case GEOMOp::OpQuadFace:         // MENU BLOCKS - QUADRANGLE FACE
501   case GEOMOp::OpPropagate:        // MENU BLOCKS - PROPAGATE
502   case GEOMOp::OpExplodeBlock:     // MENU BLOCKS - EXPLODE ON BLOCKS
503     libName = "BlocksGUI";
504     break;
505   case GEOMOp::OpAdvancedNoOp:     // NO OPERATION (advanced operations base)
506   case GEOMOp::OpPipeTShape:       // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE
507 //   case GEOMOp::OpPipeTShapeGroups:     // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE GROUPS
508     //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
509     libName = "AdvancedGUI";
510     break;
511   default:
512     break;
513   }
514
515   GEOMGUI* library = 0;
516   if ( !libName.isEmpty() ) {
517 #ifndef WNT
518     libName = QString( "lib" ) + libName + ".so";
519 #else
520     libName = libName + ".dll";
521 #endif
522     library = getLibrary( libName );
523   }
524
525   // call method of corresponding GUI library
526   if ( library )
527     library->OnGUIEvent( id, desk );
528   else
529     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
530 }
531
532 //=================================================================================
533 // function : GeometryGUI::OnKeyPress()
534 // purpose  : Called when any key is pressed by user [static]
535 //=================================================================================
536 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* w, QKeyEvent* e )
537 {
538   if ( !application() )
539     return;
540   foreach ( GEOMGUI* lib, myGUIMap )
541     lib->OnKeyPress( e, application()->desktop(), w );
542 }
543
544 //=================================================================================
545 // function : GeometryGUI::OnMouseMove()
546 // purpose  : Manages mouse move events [static]
547 //=================================================================================
548 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* w, QMouseEvent* e )
549 {
550   if ( !application() )
551     return;
552   foreach ( GEOMGUI* lib, myGUIMap )
553     lib->OnMouseMove( e, application()->desktop(), w );
554 }
555
556 //=================================================================================
557 // function : GeometryGUI::OnMousePress()
558 // purpose  : Manage mouse press events [static]
559 //=================================================================================
560 void GeometryGUI::OnMousePress( SUIT_ViewWindow* w, QMouseEvent* e )
561 {
562   if ( !application() )
563     return;
564   foreach ( GEOMGUI* lib, myGUIMap )
565     lib->OnMousePress( e, application()->desktop(), w );
566 }
567
568 //=======================================================================
569 // function : createGeomAction
570 // purpose  :
571 //=======================================================================
572 void GeometryGUI::createGeomAction( const int id, const QString& label, const QString& icolabel, const int accel, const bool toggle  )
573 {
574   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
575   QPixmap icon = icolabel.isEmpty() ? resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+label).toLatin1().constData() ), false )
576                                     : resMgr->loadPixmap( "GEOM", tr( icolabel.toLatin1().constData() ) );
577   createAction( id,
578                 tr( QString( "TOP_%1" ).arg( label ).toLatin1().constData() ),
579                 icon,
580                 tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ),
581                 tr( QString( "STB_%1" ).arg( label ).toLatin1().constData() ),
582                 accel,
583                 application()->desktop(),
584                 toggle,
585                 this, SLOT( OnGUIEvent() )  );
586 }
587
588
589
590 //=======================================================================
591 // function : GeometryGUI::initialize()
592 // purpose  : Called when GEOM module is created
593 //=======================================================================
594 void GeometryGUI::initialize( CAM_Application* app )
595 {
596   SalomeApp_Module::initialize( app );
597
598   // ----- create actions --------------
599
600   createGeomAction( GEOMOp::OpImport,     "IMPORT", "", Qt::ControlModifier + Qt::Key_I );
601   createGeomAction( GEOMOp::OpExport,     "EXPORT", "", Qt::ControlModifier + Qt::Key_E );
602
603   createGeomAction( GEOMOp::OpDelete,     "DELETE", "", Qt::Key_Delete );
604
605   createGeomAction( GEOMOp::OpPoint,      "POINT" );
606   createGeomAction( GEOMOp::OpLine,       "LINE" );
607   createGeomAction( GEOMOp::OpCircle,     "CIRCLE" );
608   createGeomAction( GEOMOp::OpEllipse,    "ELLIPSE" );
609   createGeomAction( GEOMOp::OpArc,        "ARC" );
610   createGeomAction( GEOMOp::OpCurve,      "CURVE" );
611   createGeomAction( GEOMOp::OpVector,     "VECTOR" );
612   createGeomAction( GEOMOp::OpPlane,      "PLANE" );
613   createGeomAction( GEOMOp::OpLCS,        "LOCAL_CS" );
614
615   createGeomAction( GEOMOp::OpBox,        "BOX" );
616   createGeomAction( GEOMOp::OpCylinder,   "CYLINDER" );
617   createGeomAction( GEOMOp::OpSphere,     "SPHERE" );
618   createGeomAction( GEOMOp::OpTorus,      "TORUS" );
619   createGeomAction( GEOMOp::OpCone,       "CONE" );
620   createGeomAction( GEOMOp::OpRectangle,  "RECTANGLE" );
621   createGeomAction( GEOMOp::OpDisk,       "DISK" );
622
623   createGeomAction( GEOMOp::OpPrism,       "EXTRUSION" );
624   createGeomAction( GEOMOp::OpRevolution,  "REVOLUTION" );
625   createGeomAction( GEOMOp::OpFilling,     "FILLING" );
626   createGeomAction( GEOMOp::OpPipe,        "PIPE" );
627
628   createGeomAction( GEOMOp::OpGroupCreate, "GROUP_CREATE" );
629   createGeomAction( GEOMOp::OpGroupEdit,   "GROUP_EDIT" );
630
631   createGeomAction( GEOMOp::OpReimport,    "RELOAD_IMPORTED" );
632
633   createGeomAction( GEOMOp::OpQuadFace,    "Q_FACE" );
634   createGeomAction( GEOMOp::OpHexaSolid,   "HEX_SOLID" );
635
636   createGeomAction( GEOMOp::Op2dSketcher,  "SKETCH" );
637   createGeomAction( GEOMOp::Op3dSketcher,  "3DSKETCH" );
638   createGeomAction( GEOMOp::OpExplode,     "EXPLODE" );
639
640   createGeomAction( GEOMOp::OpEdge,        "EDGE" );
641   createGeomAction( GEOMOp::OpWire,        "WIRE" );
642   createGeomAction( GEOMOp::OpFace,        "FACE" );
643   createGeomAction( GEOMOp::OpShell,       "SHELL" );
644   createGeomAction( GEOMOp::OpSolid,       "SOLID" );
645   createGeomAction( GEOMOp::OpCompound,    "COMPOUND" );
646
647   createGeomAction( GEOMOp::OpFuse,        "FUSE" );
648   createGeomAction( GEOMOp::OpCommon,      "COMMON" );
649   createGeomAction( GEOMOp::OpCut,         "CUT" );
650   createGeomAction( GEOMOp::OpSection,     "SECTION" );
651
652   createGeomAction( GEOMOp::OpTranslate,      "TRANSLATION" );
653   createGeomAction( GEOMOp::OpRotate,         "ROTATION" );
654   createGeomAction( GEOMOp::OpChangeLoc,      "MODIFY_LOCATION" );
655   createGeomAction( GEOMOp::OpMirror,         "MIRROR" );
656   createGeomAction( GEOMOp::OpScale,          "SCALE" );
657   createGeomAction( GEOMOp::OpOffset,         "OFFSET" );
658   createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" );
659   createGeomAction( GEOMOp::OpMultiRotate,    "MUL_ROTATION" );
660
661   createGeomAction( GEOMOp::OpPartition,      "PARTITION" );
662   createGeomAction( GEOMOp::OpArchimede,      "ARCHIMEDE" );
663   createGeomAction( GEOMOp::OpFillet3d,       "FILLET" );
664   createGeomAction( GEOMOp::OpChamfer,        "CHAMFER" );
665   //createGeomAction( GEOMOp::OpClipping,        "CLIPPING" );
666   createGeomAction( GEOMOp::OpShapesOnShape,  "GET_SHAPES_ON_SHAPE" );
667   createGeomAction( GEOMOp::OpSharedShapes,   "GET_SHARED_SHAPES" );
668   createGeomAction( GEOMOp::OpFillet1d,       "FILLET_1D" );
669   createGeomAction( GEOMOp::OpFillet2d,       "FILLET_2D" );
670
671   createGeomAction( GEOMOp::OpMultiTransform, "MUL_TRANSFORM" );
672   createGeomAction( GEOMOp::OpExplodeBlock,   "EXPLODE_BLOCKS" );
673   createGeomAction( GEOMOp::OpPropagate,      "PROPAGATE" );
674
675   createGeomAction( GEOMOp::OpSewing,           "SEWING" );
676   createGeomAction( GEOMOp::OpGlueFaces,        "GLUE_FACES" );
677   createGeomAction( GEOMOp::OpSuppressFaces,    "SUPPRESS_FACES" );
678   createGeomAction( GEOMOp::OpSuppressHoles,    "SUPPERSS_HOLES" );
679   createGeomAction( GEOMOp::OpShapeProcess,     "SHAPE_PROCESS" );
680   createGeomAction( GEOMOp::OpCloseContour,     "CLOSE_CONTOUR" );
681   createGeomAction( GEOMOp::OpRemoveIntWires,   "SUPPRESS_INT_WIRES" );
682   createGeomAction( GEOMOp::OpAddPointOnEdge,   "POINT_ON_EDGE" );
683   createGeomAction( GEOMOp::OpFreeBoundaries,   "CHECK_FREE_BNDS" );
684   createGeomAction( GEOMOp::OpFreeFaces,        "CHECK_FREE_FACES" );
685   createGeomAction( GEOMOp::OpOrientation,      "CHANGE_ORIENTATION" );
686   createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" );
687
688   createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" );
689   createGeomAction( GEOMOp::OpProperties,       "BASIC_PROPS" );
690   createGeomAction( GEOMOp::OpCenterMass,       "MASS_CENTER" );
691   createGeomAction( GEOMOp::OpInertia,          "INERTIA" );
692   createGeomAction( GEOMOp::OpNormale,          "NORMALE" );
693   createGeomAction( GEOMOp::OpBoundingBox,      "BND_BOX" );
694   createGeomAction( GEOMOp::OpMinDistance,      "MIN_DIST" );
695   createGeomAction( GEOMOp::OpAngle,            "MEASURE_ANGLE" );
696
697   createGeomAction( GEOMOp::OpTolerance,        "TOLERANCE" );
698   createGeomAction( GEOMOp::OpWhatIs,           "WHAT_IS" );
699   createGeomAction( GEOMOp::OpCheckShape,       "CHECK" );
700   createGeomAction( GEOMOp::OpCheckCompound,    "CHECK_COMPOUND" );
701
702 #ifdef _DEBUG_ // PAL16821
703   createGeomAction( GEOMOp::OpCheckGeom,        "CHECK_GEOMETRY" );
704 #endif
705
706   createGeomAction( GEOMOp::OpDisplayMode,      "SHADING" );
707   createGeomAction( GEOMOp::OpShowAll,          "DISPLAY_ALL" );
708   createGeomAction( GEOMOp::OpHideAll,          "ERASE_ALL" );
709   createGeomAction( GEOMOp::OpShow,             "DISPLAY" );
710   createGeomAction( GEOMOp::OpSwitchVectors,    "VECTOR_MODE");
711   createGeomAction( GEOMOp::OpSelectVertex,     "VERTEX_SEL_ONLY" ,"", 0, true );
712   createGeomAction( GEOMOp::OpSelectEdge,       "EDGE_SEL_ONLY", "", 0, true );
713   createGeomAction( GEOMOp::OpSelectWire,       "WIRE_SEL_ONLY", "",  0, true );
714   createGeomAction( GEOMOp::OpSelectFace,       "FACE_SEL_ONLY", "", 0, true );
715   createGeomAction( GEOMOp::OpSelectShell,      "SHELL_SEL_ONLY", "",  0, true );
716   createGeomAction( GEOMOp::OpSelectSolid,      "SOLID_SEL_ONLY", "", 0, true );
717   createGeomAction( GEOMOp::OpSelectCompound,   "COMPOUND_SEL_ONLY", "",  0, true );
718   createGeomAction( GEOMOp::OpSelectAll,        "ALL_SEL_ONLY", "",  0, true );
719   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
720   createGeomAction( GEOMOp::OpHide,             "ERASE" );
721
722   createGeomAction( GEOMOp::OpRename,           "POP_RENAME", "", Qt::Key_F2 );
723   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
724   createGeomAction( GEOMOp::OpShading,          "POP_SHADING", "", 0, true );
725   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
726   createGeomAction( GEOMOp::OpDeflection,       "POP_DEFLECTION" );
727   createGeomAction( GEOMOp::OpColor,            "POP_COLOR" );
728   createGeomAction( GEOMOp::OpTransparency,     "POP_TRANSPARENCY" );
729   createGeomAction( GEOMOp::OpIsos,             "POP_ISOS" );
730   createGeomAction( GEOMOp::OpAutoColor,        "POP_AUTO_COLOR" );
731   createGeomAction( GEOMOp::OpNoAutoColor,      "POP_DISABLE_AUTO_COLOR" );
732   createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
733   createGeomAction( GEOMOp::OpShowChildren,     "POP_SHOW_CHILDREN" );
734   createGeomAction( GEOMOp::OpHideChildren,     "POP_HIDE_CHILDREN" );
735   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
736
737   createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
738 //   createGeomAction( GEOMOp::OpPipeTShapeGroups, "PIPETSHAPEGROUPS" );
739   //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
740
741   // ---- create menus --------------------------
742
743   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
744   createMenu( separator(),      fileId, 10 );
745   createMenu( GEOMOp::OpImport, fileId, 10 );
746   createMenu( GEOMOp::OpExport, fileId, 10 );
747   createMenu( separator(),      fileId, -1 );
748
749   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
750   createMenu( GEOMOp::OpDelete, editId, -1 );
751
752   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
753
754   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
755   createMenu( GEOMOp::OpPoint,   basicId, -1 );
756   createMenu( GEOMOp::OpLine,    basicId, -1 );
757   createMenu( GEOMOp::OpCircle,  basicId, -1 );
758   createMenu( GEOMOp::OpEllipse, basicId, -1 );
759   createMenu( GEOMOp::OpArc,     basicId, -1 );
760   createMenu( GEOMOp::OpCurve,   basicId, -1 );
761   createMenu( separator(),       basicId, -1 );
762   createMenu( GEOMOp::OpVector,  basicId, -1 );
763   createMenu( GEOMOp::OpPlane,   basicId, -1 );
764   createMenu( GEOMOp::OpLCS,     basicId, -1 );
765
766   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
767   createMenu( GEOMOp::OpBox,       primId, -1 );
768   createMenu( GEOMOp::OpCylinder,  primId, -1 );
769   createMenu( GEOMOp::OpSphere,    primId, -1 );
770   createMenu( GEOMOp::OpTorus,     primId, -1 );
771   createMenu( GEOMOp::OpCone,      primId, -1 );
772   createMenu( GEOMOp::OpRectangle, primId, -1 );
773   createMenu( GEOMOp::OpDisk,      primId, -1 );
774
775   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
776   createMenu( GEOMOp::OpPrism,      genId, -1 );
777   createMenu( GEOMOp::OpRevolution, genId, -1 );
778   createMenu( GEOMOp::OpFilling,    genId, -1 );
779   createMenu( GEOMOp::OpPipe,       genId, -1 );
780
781   int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
782   createMenu( GEOMOp::OpPipeTShape, advId, -1 );
783 //   createMenu( GEOMOp::OpPipeTShapeGroups, advId, -1 );
784   //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
785
786   createMenu( separator(), newEntId, -1 );
787
788   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
789   createMenu( GEOMOp::OpGroupCreate, groupId, -1 );
790   createMenu( GEOMOp::OpGroupEdit,   groupId, -1 );
791
792   createMenu( separator(), newEntId, -1 );
793
794   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
795   createMenu( GEOMOp::OpQuadFace,  blocksId, -1 );
796   createMenu( GEOMOp::OpHexaSolid, blocksId, -1 );
797
798   createMenu( separator(),          newEntId, -1 );
799
800   createMenu( GEOMOp::Op2dSketcher, newEntId, -1 );
801   createMenu( GEOMOp::Op3dSketcher, newEntId, -1 );
802
803   createMenu( separator(),          newEntId, -1 );
804
805   createMenu( GEOMOp::OpExplode,    newEntId, -1 );
806
807   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
808   createMenu( GEOMOp::OpEdge,     buildId, -1 );
809   createMenu( GEOMOp::OpWire,     buildId, -1 );
810   createMenu( GEOMOp::OpFace,     buildId, -1 );
811   createMenu( GEOMOp::OpShell,    buildId, -1 );
812   createMenu( GEOMOp::OpSolid,    buildId, -1 );
813   createMenu( GEOMOp::OpCompound, buildId, -1 );
814
815   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
816
817   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
818   createMenu( GEOMOp::OpFuse,    boolId, -1 );
819   createMenu( GEOMOp::OpCommon,  boolId, -1 );
820   createMenu( GEOMOp::OpCut,     boolId, -1 );
821   createMenu( GEOMOp::OpSection, boolId, -1 );
822
823   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
824   createMenu( GEOMOp::OpTranslate,      transId, -1 );
825   createMenu( GEOMOp::OpRotate,         transId, -1 );
826   createMenu( GEOMOp::OpChangeLoc,      transId, -1 );
827   createMenu( GEOMOp::OpMirror,         transId, -1 );
828   createMenu( GEOMOp::OpScale,          transId, -1 );
829   createMenu( GEOMOp::OpOffset,         transId, -1 );
830   createMenu( separator(),              transId, -1 );
831   createMenu( GEOMOp::OpMultiTranslate, transId, -1 );
832   createMenu( GEOMOp::OpMultiRotate,    transId, -1 );
833
834   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
835   createMenu( GEOMOp::OpMultiTransform, blockId, -1 );
836   createMenu( GEOMOp::OpExplodeBlock,   blockId, -1 );
837   createMenu( GEOMOp::OpPropagate,      blockId, -1 );
838
839   createMenu( separator(), operId, -1 );
840
841   createMenu( GEOMOp::OpPartition,     operId, -1 );
842   createMenu( GEOMOp::OpArchimede,     operId, -1 );
843   createMenu( GEOMOp::OpShapesOnShape, operId, -1 );
844   createMenu( GEOMOp::OpSharedShapes,  operId, -1 );
845
846   createMenu( separator(), operId, -1 );
847
848   createMenu( GEOMOp::OpFillet1d,      operId, -1 );
849   createMenu( GEOMOp::OpFillet2d,      operId, -1 );
850   createMenu( GEOMOp::OpFillet3d,      operId, -1 );
851   createMenu( GEOMOp::OpChamfer,       operId, -1 );
852   //createMenu( GEOMOp::OpClipping,      operId, -1 );
853
854   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
855   createMenu( GEOMOp::OpShapeProcess,    repairId, -1 );
856   createMenu( GEOMOp::OpSuppressFaces,   repairId, -1 );
857   createMenu( GEOMOp::OpCloseContour,    repairId, -1 );
858   createMenu( GEOMOp::OpRemoveIntWires,  repairId, -1 );
859   createMenu( GEOMOp::OpSuppressHoles,   repairId, -1 );
860   createMenu( GEOMOp::OpSewing,          repairId, -1 );
861   createMenu( GEOMOp::OpGlueFaces,       repairId, -1 );
862   createMenu( GEOMOp::OpAddPointOnEdge,  repairId, -1 );
863   //createMenu( GEOMOp::OpFreeBoundaries,  repairId, -1 );
864   //createMenu( GEOMOp::OpFreeFaces,       repairId, -1 );
865   createMenu( GEOMOp::OpOrientation,      repairId, -1 );
866   createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 );
867
868   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
869   createMenu( GEOMOp::OpPointCoordinates, measurId, -1 );
870   createMenu( GEOMOp::OpProperties,       measurId, -1 );
871   createMenu( separator(),                measurId, -1 );
872   createMenu( GEOMOp::OpCenterMass,       measurId, -1 );
873   createMenu( GEOMOp::OpInertia,          measurId, -1 );
874   createMenu( GEOMOp::OpNormale,          measurId, -1 );
875   createMenu( separator(),                measurId, -1 );
876   createMenu( GEOMOp::OpFreeBoundaries,   measurId, -1 );
877   createMenu( GEOMOp::OpFreeFaces,        measurId, -1 );
878   createMenu( separator(),                measurId, -1 );
879
880   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
881   createMenu( GEOMOp::OpBoundingBox, dimId, -1 );
882   createMenu( GEOMOp::OpMinDistance, dimId, -1 );
883   createMenu( GEOMOp::OpAngle,       dimId, -1 );
884
885   createMenu( separator(),             measurId, -1 );
886   createMenu( GEOMOp::OpTolerance,     measurId, -1 );
887   createMenu( separator(),             measurId, -1 );
888   createMenu( GEOMOp::OpWhatIs,        measurId, -1 );
889   createMenu( GEOMOp::OpCheckShape,    measurId, -1 );
890   createMenu( GEOMOp::OpCheckCompound, measurId, -1 );
891
892 #ifdef _DEBUG_ // PAL16821
893   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
894   createMenu( separator(),         toolsId, -1 );
895   createMenu( GEOMOp::OpCheckGeom, toolsId, -1 );
896 #endif
897
898   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
899   createMenu( separator(),       viewId, -1 );
900
901   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
902   createMenu( GEOMOp::OpDisplayMode,   dispmodeId, -1 );
903   createMenu( separator(),             dispmodeId, -1 );
904   createMenu( GEOMOp::OpSwitchVectors, dispmodeId, -1 );
905
906   createMenu( separator(),       viewId, -1 );
907   createMenu( GEOMOp::OpShowAll, viewId, -1 );
908   createMenu( GEOMOp::OpHideAll, viewId, -1 );
909   createMenu( separator(),       viewId, -1 );
910
911 /*
912   PAL9111:
913   because of these items are accessible through object browser and viewers
914   we have removed they from main menu
915
916   createMenu( GEOMOp::OpShow, viewId, -1 );
917   createMenu( GEOMOp::OpShowOnly, viewId, -1 );
918   createMenu( GEOMOp::OpHide, viewId, -1 );
919 */
920
921   // ---- create toolbars --------------------------
922
923   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
924   createTool( GEOMOp::OpPoint,   basicTbId );
925   createTool( GEOMOp::OpLine,    basicTbId );
926   createTool( GEOMOp::OpCircle,  basicTbId );
927   createTool( GEOMOp::OpEllipse, basicTbId );
928   createTool( GEOMOp::OpArc,     basicTbId );
929   createTool( GEOMOp::OpCurve,   basicTbId );
930   createTool( GEOMOp::OpVector,  basicTbId );
931   createTool( GEOMOp::OpPlane,   basicTbId );
932   createTool( GEOMOp::OpLCS,     basicTbId );
933
934   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
935   createTool( GEOMOp::OpBox,       primTbId );
936   createTool( GEOMOp::OpCylinder,  primTbId );
937   createTool( GEOMOp::OpSphere,    primTbId );
938   createTool( GEOMOp::OpTorus,     primTbId );
939   createTool( GEOMOp::OpCone,      primTbId );
940   createTool( GEOMOp::OpRectangle, primTbId );
941   createTool( GEOMOp::OpDisk,      primTbId );
942
943   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
944   createTool( GEOMOp::OpFuse,    boolTbId );
945   createTool( GEOMOp::OpCommon,  boolTbId );
946   createTool( GEOMOp::OpCut,     boolTbId );
947   createTool( GEOMOp::OpSection, boolTbId );
948
949   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
950   createTool( GEOMOp::OpPrism,      genTbId );
951   createTool( GEOMOp::OpRevolution, genTbId );
952   createTool( GEOMOp::OpFilling,    genTbId );
953   createTool( GEOMOp::OpPipe,       genTbId );
954
955   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
956   createTool( GEOMOp::OpTranslate,      transTbId );
957   createTool( GEOMOp::OpRotate,         transTbId );
958   createTool( GEOMOp::OpChangeLoc,      transTbId );
959   createTool( GEOMOp::OpMirror,         transTbId );
960   createTool( GEOMOp::OpScale,          transTbId );
961   createTool( GEOMOp::OpOffset,         transTbId );
962   createTool( separator(),              transTbId );
963   createTool( GEOMOp::OpMultiTranslate, transTbId );
964   createTool( GEOMOp::OpMultiRotate,    transTbId );
965
966   int operTbId = createTool( tr( "TOOL_OPERATIONS" ) );
967   createTool( GEOMOp::Op2dSketcher,      operTbId );
968   createTool( GEOMOp::Op3dSketcher,      operTbId );
969   createTool( separator(),               operTbId );
970   createTool( GEOMOp::OpExplode,         operTbId );
971   createTool( separator(),               operTbId );
972   createTool( GEOMOp::OpPartition,       operTbId );
973   createTool( GEOMOp::OpArchimede,       operTbId );
974   createTool( GEOMOp::OpShapesOnShape,   operTbId );
975   createTool( GEOMOp::OpSharedShapes,    operTbId );
976   createTool( separator(),               operTbId );
977   createTool( GEOMOp::OpFillet1d,        operTbId );
978   createTool( GEOMOp::OpFillet2d,        operTbId );
979   createTool( GEOMOp::OpFillet3d,        operTbId );
980   createTool( GEOMOp::OpChamfer,         operTbId );
981
982   int buildTbId = createTool( tr( "TOOL_BUILD" ) );
983   createTool( GEOMOp::OpEdge,     buildTbId );
984   createTool( GEOMOp::OpWire,     buildTbId );
985   createTool( GEOMOp::OpFace,     buildTbId );
986   createTool( GEOMOp::OpShell,    buildTbId );
987   createTool( GEOMOp::OpSolid,    buildTbId );
988   createTool( GEOMOp::OpCompound, buildTbId );
989
990   int measureTbId = createTool( tr( "TOOL_MEASURES" ) );
991   createTool( GEOMOp::OpPointCoordinates, measureTbId );
992   createTool( GEOMOp::OpProperties,       measureTbId );
993   createTool( GEOMOp::OpCenterMass,       measureTbId );
994   createTool( GEOMOp::OpInertia,          measureTbId );
995   createTool( GEOMOp::OpNormale,          measureTbId );
996   createTool( separator(),                measureTbId );
997   createTool( GEOMOp::OpBoundingBox,      measureTbId );
998   createTool( GEOMOp::OpMinDistance,      measureTbId );
999   createTool( GEOMOp::OpAngle,            measureTbId );
1000   createTool( GEOMOp::OpTolerance  ,      measureTbId );
1001   createTool( separator(),                measureTbId );
1002   createTool( GEOMOp::OpFreeBoundaries,   measureTbId );
1003   createTool( GEOMOp::OpFreeFaces,        measureTbId );
1004   createTool( separator(),                measureTbId );
1005   createTool( GEOMOp::OpWhatIs,           measureTbId );
1006   createTool( GEOMOp::OpCheckShape,       measureTbId );
1007   createTool( GEOMOp::OpCheckCompound,    measureTbId );
1008
1009   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
1010   createTool( GEOMOp::OpPipeTShape, advancedTbId );
1011   //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@//
1012
1013   // ---- create popup menus --------------------------
1014
1015   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1016   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1017
1018   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1019   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1020
1021   QString autoColorPrefix =
1022     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1023
1024   QtxPopupMgr* mgr = popupMgr();
1025   mgr->insert( action(  GEOMOp::OpRename ), -1, -1 );  // rename
1026   mgr->setRule( action( GEOMOp::OpRename ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
1027   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
1028   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1029   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
1030   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1031   mgr->insert( action(  GEOMOp::OpShowChildren ), -1, -1 ); // show children
1032   mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1033   mgr->insert( action(  GEOMOp::OpHideChildren ), -1, -1 ); // hide children
1034   mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1035   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1036   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1037   mgr->insert( separator(), -1, -1 );     // -----------
1038   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1039   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1040   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1041   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1042   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1043   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1044   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1045   mgr->insert( separator(), dispmodeId, -1 );
1046   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1047   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1048   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1049   mgr->insert( separator(), -1, -1 );     // -----------
1050   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1051   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1052   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1053   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1054   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1055   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1056   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1057   mgr->setRule( action( GEOMOp::OpDeflection ), "selcount>0 and isVisible and client='OCCViewer'", QtxPopupMgr::VisibleRule );
1058   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1059   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg( GEOM_POINT ), QtxPopupMgr::VisibleRule );
1060   mgr->insert( separator(), -1, -1 );     // -----------
1061   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1062   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1063   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1064   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1065   mgr->insert( separator(), -1, -1 );     // -----------
1066
1067   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1068           onlyComponent = "((type='Component') and selcount=1)",
1069           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1070           types = "'Shape' 'Group'";
1071
1072   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1073   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1074
1075   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1076   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1077
1078   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1079   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1080
1081   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1082
1083   int selectonlyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1084   mgr->insert( action(GEOMOp::OpSelectVertex),   selectonlyId, -1);                                  //Vertex
1085   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1086   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1087   mgr->insert( action(GEOMOp::OpSelectEdge),     selectonlyId, -1);                                  //Edge
1088   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1089   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1090   mgr->insert( action(GEOMOp::OpSelectWire),     selectonlyId, -1);                                  //Wire
1091   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1092   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1093   mgr->insert( action(GEOMOp::OpSelectFace),     selectonlyId, -1);                                  //Face
1094   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1095   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1096   mgr->insert( action(GEOMOp::OpSelectShell),    selectonlyId, -1);                                  //Shell
1097   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1098   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1099   mgr->insert( action(GEOMOp::OpSelectSolid),    selectonlyId, -1);                                  //Solid
1100   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1101   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1102   mgr->insert( action(GEOMOp::OpSelectCompound), selectonlyId, -1);                                  //Compound
1103   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1104   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1105   mgr->insert( separator(), selectonlyId, -1);
1106   mgr->insert( action(GEOMOp::OpSelectAll),      selectonlyId, -1);                                  //Clear selection filter
1107   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1108   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1109   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1110   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1111   mgr->insert( separator(), -1, -1 );
1112
1113   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1114 }
1115
1116 //=======================================================================
1117 // function : GeometryGUI::activateModule()
1118 // purpose  : Called when GEOM module is activated
1119 //=======================================================================
1120 bool GeometryGUI::activateModule( SUIT_Study* study )
1121 {
1122   if ( CORBA::is_nil( myComponentGeom ) )
1123     return false;
1124
1125   bool res = SalomeApp_Module::activateModule( study );
1126
1127   if ( !res )
1128     return false;
1129
1130   setMenuShown( true );
1131   setToolShown( true );
1132
1133   // import Python module that manages GEOM plugins (need to be here because SalomePyQt API uses active module)
1134   PyGILState_STATE gstate = PyGILState_Ensure();
1135   PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
1136   if(pluginsmanager==NULL)
1137     PyErr_Print();
1138   else
1139     {
1140       PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"geom","New Entity","Other");
1141       if(result==NULL)
1142         PyErr_Print();
1143       Py_XDECREF(result);
1144     }
1145   PyGILState_Release(gstate);
1146   // end of GEOM plugins loading
1147
1148   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1149           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1150
1151   // Reset actions accelerator keys
1152   action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
1153   action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
1154   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1155   action(GEOMOp::OpRename)->setEnabled( true ); // Rename: Key_F2
1156
1157   GUIMap::Iterator it;
1158   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1159     it.value()->activate( application()->desktop() );
1160
1161   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1162
1163   SUIT_ViewManager* vm;
1164   ViewManagerList OCCViewManagers, VTKViewManagers;
1165
1166   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1167   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1168   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1169     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1170
1171   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1172   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1173   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1174     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1175
1176   //NPAL 19674
1177   SALOME_ListIO selected;
1178   sm->selectedObjects( selected );
1179   sm->clearSelected();
1180
1181   // disable OCC selectors
1182   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1183   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1184   while ( itOCCSel.hasNext() )
1185     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1186       sr->setEnabled(true);
1187
1188   // disable VTK selectors
1189   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1190   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1191   while ( itVTKSel.hasNext() )
1192     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1193       sr->setEnabled(true);
1194
1195   sm->setSelectedObjects( selected, true );   //NPAL 19674
1196
1197   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1198   if ( viewMenu )
1199     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1200
1201   return true;
1202 }
1203
1204
1205 //=======================================================================
1206 // function : GeometryGUI::deactivateModule()
1207 // purpose  : Called when GEOM module is deactivated
1208 //=======================================================================
1209 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1210 {
1211   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1212   if ( viewMenu )
1213     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1214
1215   setMenuShown( false );
1216   setToolShown( false );
1217
1218   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1219              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1220
1221   EmitSignalCloseAllDialogs();
1222
1223   GUIMap::Iterator it;
1224   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1225     it.value()->deactivate();
1226
1227   // Unset actions accelerator keys
1228   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1229   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1230   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1231   action(GEOMOp::OpRename)->setEnabled( false ); // Rename: Key_F2
1232
1233   qDeleteAll(myOCCSelectors);
1234   myOCCSelectors.clear();
1235   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1236
1237   qDeleteAll(myVTKSelectors);
1238   myVTKSelectors.clear();
1239   getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1240
1241   return SalomeApp_Module::deactivateModule( study );
1242 }
1243
1244 //=======================================================================
1245 // function : onWindowActivated()
1246 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1247 //=======================================================================
1248 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1249 {
1250   if ( !win )
1251     return;
1252
1253   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1254   //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1255
1256   // disable non-OCC viewframe menu commands
1257 //  action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
1258   action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
1259   action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
1260   action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
1261   action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
1262   action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
1263 //  action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
1264
1265   action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
1266   action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
1267
1268   action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1269 }
1270
1271 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1272 {
1273   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1274   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1275 }
1276
1277 void GeometryGUI::viewManagers( QStringList& lst ) const
1278 {
1279   lst.append( OCCViewer_Viewer::Type() );
1280 }
1281
1282 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1283 {
1284   if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
1285   {
1286     qDebug( "connect" );
1287     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1288              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1289     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1290              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1291     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1292              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1293
1294     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1295     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1296
1297     // disable OCC selectors
1298     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1299     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1300     while ( itOCCSel.hasNext() )
1301       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1302         sr->setEnabled(true);
1303   }
1304   else if ( vm->getType() == SVTK_Viewer::Type() )
1305   {
1306     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1307     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1308
1309     // disable VTK selectors
1310     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1311     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1312     while ( itVTKSel.hasNext() )
1313       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1314         sr->setEnabled(true);
1315   }
1316 }
1317
1318 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1319 {
1320   SUIT_ViewModel* viewer = vm->getViewModel();
1321   if ( vm->getType() == OCCViewer_Viewer::Type() )
1322   {
1323     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1324     while ( itOCCSel.hasNext() )
1325       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1326         if ( sr->viewer() == viewer )
1327         {
1328           delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1329           break;
1330         }
1331   }
1332   if ( vm->getType() == SVTK_Viewer::Type() )
1333   {
1334     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1335     while ( itVTKSel.hasNext() )
1336       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1337         if ( sr->viewer() == viewer )
1338         {
1339           delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1340           break;
1341         }
1342   }
1343 }
1344
1345 QString GeometryGUI::engineIOR() const
1346 {
1347   if ( !CORBA::is_nil( GetGeomGen() ) )
1348     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1349   return "";
1350 }
1351
1352 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture( SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight )
1353 {
1354   theWidth = theHeight = 0;
1355   Handle(Graphic3d_HArray1OfBytes) aTexture;
1356   if ( theStudy ) {
1357     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1358     aTexture = aTextureMap[ theId ];
1359     if ( aTexture.IsNull() ) {
1360       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1361       if ( !aInsOp->_is_nil() ) {
1362         CORBA::Long aWidth, aHeight;
1363         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1364         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1365           theWidth  = aWidth;
1366           theHeight = aHeight;
1367           aTexture  = new Graphic3d_HArray1OfBytes( 1, aStream->length() );
1368           for ( int i = 0; i < aStream->length(); i++ )
1369             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1370           aTextureMap[ theId ] = aTexture;
1371         }
1372       }
1373     }
1374   }
1375   return aTexture;
1376 }
1377
1378 LightApp_Selection* GeometryGUI::createSelection() const
1379 {
1380   return new GEOMGUI_Selection();
1381 }
1382
1383 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1384 {
1385   SalomeApp_Module::contextMenuPopup(client, menu, title);
1386
1387   SALOME_ListIO lst;
1388   getApp()->selectionMgr()->selectedObjects(lst);
1389   if (lst.Extent() < 1)
1390     return;
1391
1392   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1393   _PTR(Study) study = appStudy->studyDS();
1394
1395   bool isImported = true;
1396   SALOME_ListIteratorOfListIO anIt (lst);
1397   for (; anIt.More() && isImported; anIt.Next()) {
1398     Handle(SALOME_InteractiveObject) io = anIt.Value();
1399     _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1400     if (aSObj) {
1401       if (lst.Extent() == 1) {
1402         // Set context menu title
1403         if (client == "OCCViewer" || client == "VTKViewer")
1404           title = QString(aSObj->GetName().c_str());
1405       }
1406
1407       CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1408       GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1409       if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1410         isImported = false;
1411     } else {
1412       isImported = false;
1413     }
1414   }
1415
1416   if (isImported) {
1417     menu->addAction(action(GEOMOp::OpReimport)); // Reload imported shape
1418   }
1419 }
1420
1421 void GeometryGUI::createPreferences()
1422 {
1423   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1424
1425   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1426   setPreferenceProperty( genGroup, "columns", 2 );
1427
1428   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1429                                 LightApp_Preferences::Selector,
1430                                 "Geometry", "display_mode" );
1431
1432   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1433                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1434
1435   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1436                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1437
1438   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1439                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1440
1441   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1442                  LightApp_Preferences::Color, "Geometry", "line_color" );
1443
1444   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1445                  LightApp_Preferences::Color, "Geometry", "point_color" );
1446
1447   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1448                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1449
1450   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1451                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1452
1453   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
1454                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
1455
1456   // Quantities with individual precision settings
1457   int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
1458   setPreferenceProperty( precGroup, "columns", 2 );
1459
1460   const int nbQuantities = 8;
1461   int prec[nbQuantities], ii = 0;
1462   prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
1463                             LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
1464   prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
1465                             LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
1466   prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
1467                             LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
1468   prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
1469                             LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
1470   prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
1471                             LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
1472   prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
1473                             LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
1474   prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
1475                             LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
1476   prec[ii  ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
1477                             LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
1478
1479   // Set property for precision value for spinboxes
1480   for ( ii = 0; ii < nbQuantities; ii++ ){
1481     setPreferenceProperty( prec[ii], "min", -14 );
1482     setPreferenceProperty( prec[ii], "max", 14 );
1483     setPreferenceProperty( prec[ii], "precision", 2 );
1484   }
1485
1486   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1487   setPreferenceProperty( VertexGroup, "columns", 2 );
1488
1489   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1490                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1491
1492   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1493                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
1494
1495   // Set property for default display mode
1496   QStringList aModesList;
1497   aModesList.append( tr("MEN_WIREFRAME") );
1498   aModesList.append( tr("MEN_SHADING") );
1499
1500   QList<QVariant> anIndexesList;
1501   anIndexesList.append(0);
1502   anIndexesList.append(1);
1503
1504   setPreferenceProperty( dispmode, "strings", aModesList );
1505   setPreferenceProperty( dispmode, "indexes", anIndexesList );
1506
1507   // Set property for step value for spinboxes
1508   setPreferenceProperty( step, "min", 1 );
1509   setPreferenceProperty( step, "max", 10000 );
1510   setPreferenceProperty( step, "precision", 3 );
1511
1512   // Set property for deflection value for spinboxes
1513   setPreferenceProperty( defl, "min", DEFLECTION_MIN );
1514   setPreferenceProperty( defl, "max", 1.0 );
1515   setPreferenceProperty( defl, "step", 1.0e-04 );
1516   setPreferenceProperty( defl, "precision", 6 );
1517
1518   // Set property vertex marker type
1519   QList<QVariant> aMarkerTypeIndicesList;
1520   QList<QVariant> aMarkerTypeIconsList;
1521
1522   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1523   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
1524     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
1525     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
1526     aMarkerTypeIndicesList << (i-1);
1527     aMarkerTypeIconsList << pixmap;
1528   }
1529
1530   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
1531   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
1532
1533   // Set property for vertex marker scale
1534   QList<QVariant> aMarkerScaleIndicesList;
1535   QStringList     aMarkerScaleValuesList;
1536
1537   for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
1538     aMarkerScaleIndicesList << iii;
1539     aMarkerScaleValuesList  << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
1540   }
1541
1542   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
1543   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
1544 }
1545
1546 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1547 {
1548   if (section == "Geometry") {
1549     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1550     if (param == QString("SettingsGeomStep")) {
1551       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1552       EmitSignalDefaultStepValueChanged(spin_step);
1553     }
1554   }
1555 }
1556
1557 LightApp_Displayer* GeometryGUI::displayer()
1558 {
1559   if( !myDisplayer )
1560     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1561   return myDisplayer;
1562 }
1563
1564 void GeometryGUI::setLocalSelectionMode(const int mode)
1565 {
1566   myLocalSelectionMode = mode;
1567 }
1568 int GeometryGUI::getLocalSelectionMode() const
1569 {
1570   return myLocalSelectionMode;
1571 }
1572
1573 const char gSeparator = '_'; // character used to separate parameter names
1574 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1575
1576 /*!
1577  * \brief Store visual parameters
1578  *
1579  * This method is called just before the study document is saved.
1580  * Store visual parameters in AttributeParameter attribue(s)
1581  */
1582 void GeometryGUI::storeVisualParameters (int savePoint)
1583 {
1584   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1585   if (!appStudy || !appStudy->studyDS())
1586     return;
1587   _PTR(Study) studyDS = appStudy->studyDS();
1588
1589   // componentName is used for encoding of entries when storing them in IParameters
1590   std::string componentName = myComponentGeom->ComponentDataType();
1591   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1592   //if (!aSComponent) return;
1593
1594   // IParameters
1595   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1596                                                              componentName.c_str(),
1597                                                              savePoint);
1598   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1599
1600   // viewers counters are used for storing view_numbers in IParameters
1601   int vtkViewers(0), occViewers(0);
1602
1603   QList<SUIT_ViewManager*> lst;
1604   QList<SUIT_ViewManager*>::Iterator it;
1605
1606   // main cycle to store parameters of displayed objects
1607   lst.clear();
1608   vtkViewers = occViewers = 0;
1609   getApp()->viewManagers(lst);
1610   for (it = lst.begin(); it != lst.end(); it++)
1611   {
1612     SUIT_ViewManager* vman = *it;
1613     QString vType = vman->getType();
1614
1615     // saving VTK actors properties
1616     if (vType == SVTK_Viewer::Type())
1617     {
1618       QVector<SUIT_ViewWindow*> views = vman->getViews();
1619       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1620       {
1621         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
1622         {
1623           vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1624           allActors->InitTraversal();
1625           while (vtkActor* actor = allActors->GetNextActor())
1626           {
1627             if (actor->GetVisibility()) // store only visible actors
1628             {
1629               GEOM_Actor* aGeomActor = 0;
1630               if (actor->IsA("GEOM_Actor"))
1631                 aGeomActor = GEOM_Actor::SafeDownCast(actor);
1632               if (aGeomActor && aGeomActor->hasIO())
1633               {
1634                 Handle(SALOME_InteractiveObject) io = aGeomActor->getIO();
1635                 if (io->hasEntry())
1636                 {
1637                   // entry is "encoded" = it does NOT contain component adress, since it is a
1638                   // subject to change on next component loading
1639                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1640
1641                   std::string param, occParam = vType.toLatin1().data();
1642                   occParam += gSeparator;
1643                   occParam += QString::number(vtkViewers).toLatin1().data();
1644                   occParam += gSeparator;
1645
1646                   param = occParam + "Visibility";
1647                   ip->setParameter(entry, param, "On");
1648
1649                   param = occParam + "DisplayMode";
1650                   ip->setParameter(entry, param, QString::number
1651                                    (aGeomActor->getDisplayMode()).toLatin1().data());
1652
1653                   vtkFloatingPointType r, g, b;
1654                   aGeomActor->GetColor(r, g, b);
1655                   QString colorStr = QString::number(r);
1656                   colorStr += gDigitsSep; colorStr += QString::number(g);
1657                   colorStr += gDigitsSep; colorStr += QString::number(b);
1658                   param = occParam + "Color";
1659                   ip->setParameter(entry, param, colorStr.toLatin1().data());
1660
1661                   param = occParam + "Opacity";
1662                   ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data());
1663
1664                   int nbUIso(0), nbVIso(0);
1665                   aGeomActor->GetNbIsos(nbUIso,nbVIso);
1666                   QString isosStr = QString::number(nbUIso);
1667                   isosStr += gDigitsSep;
1668                   isosStr += QString::number(nbVIso);
1669                   param = occParam + "Isos";
1670                   ip->setParameter(entry, param, isosStr.toLatin1().data());
1671                 } // if (io->hasEntry())
1672               } // GEOM_Actor && hasIO
1673             } // isVisible
1674           } // while.. actors traversal
1675         } // if (vtkView)
1676       } // for (views)
1677       vtkViewers++;
1678     } // if (SVTK view model)
1679     else if (vType == SOCC_Viewer::Type()) // processing OCC viewers
1680     {
1681       QVector<SUIT_ViewWindow*> views = vman->getViews();
1682       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1683       {
1684         SOCC_ViewWindow* occView = dynamic_cast<SOCC_ViewWindow*>(views[i]);
1685         if (occView)
1686         {
1687           //Handle(AIS_InteractiveContext) ic =
1688           //  ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext();
1689           OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel());
1690           //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer();
1691           Handle(AIS_InteractiveContext) ic = viewModel->getAISContext();
1692
1693           AIS_ListOfInteractive aList;
1694           ic->DisplayedObjects(aList);
1695
1696           AIS_ListIteratorOfListOfInteractive ite (aList);
1697           for (; ite.More(); ite.Next())
1698           {
1699             if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
1700             {
1701               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1702               if (aSh->hasIO())
1703               {
1704                 Handle(SALOME_InteractiveObject) io =
1705                   Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1706                 if (io->hasEntry())
1707                 {
1708                   // entry is "encoded": it does NOT contain component adress,
1709                   // since it is a subject to change on next component loading
1710                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1711
1712                   std::string param, occParam = vType.toLatin1().data();
1713                   occParam += gSeparator;
1714                   occParam += QString::number(occViewers).toLatin1().data();
1715                   occParam += gSeparator;
1716
1717                   // Visibility
1718                   param = occParam + "Visibility";
1719                   ip->setParameter(entry, param, "On");
1720
1721                   // DisplayMode
1722                   param = occParam + "DisplayMode";
1723                   int dm = aSh->DisplayMode();
1724                   ip->setParameter(entry, param, QString::number(dm).toLatin1().data());
1725
1726                   // Color
1727                   // is a property of GEOM_Object, it is stored by GEOM engine
1728
1729                   // Transparency
1730                   param = occParam + "Transparency";
1731                   ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data());
1732
1733                   // Isos
1734                   Handle(AIS_Drawer) aDrawer = aSh->Attributes();
1735                   int nbUIso = aDrawer->UIsoAspect()->Number();
1736                   int nbVIso = aDrawer->VIsoAspect()->Number();
1737                   QString isosStr = QString::number(nbUIso);
1738                   isosStr += gDigitsSep;
1739                   isosStr += QString::number(nbVIso);
1740                   param = occParam + "Isos";
1741                   ip->setParameter(entry, param, isosStr.toLatin1().data());
1742                 } // if (io->hasEntry())
1743               } // if (io)
1744             } // if (GEOM_AISShape)
1745           } // for (AIS_ListOfInteractive)
1746         } // if ( occView )
1747       } // for ( views )
1748       occViewers++;
1749     } // if (SOCC view model)
1750     else
1751     {
1752       // unknown viewer type
1753     }
1754   } // for (viewManagers)
1755 }
1756
1757 /*!
1758  * \brief Restore visual parameters
1759  *
1760  * This method is called after the study document is opened.
1761  * Restore visual parameters from AttributeParameter attribue(s)
1762  */
1763 void GeometryGUI::restoreVisualParameters (int savePoint)
1764 {
1765   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1766   if (!appStudy || !appStudy->studyDS())
1767     return;
1768   _PTR(Study) studyDS = appStudy->studyDS();
1769
1770   // componentName is used for encoding of entries when storing them in IParameters
1771   std::string componentName = myComponentGeom->ComponentDataType();
1772   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1773   //if (!aSComponent) return;
1774
1775   // IParameters
1776   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1777                                                              componentName.c_str(),
1778                                                              savePoint);
1779   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1780
1781   std::vector<std::string> entries = ip->getEntries();
1782
1783   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1784   {
1785     // entry is a normal entry - it should be "decoded" (setting base adress of component)
1786     QString entry (ip->decodeEntry(*entIt).c_str());
1787
1788     // Check that the entry corresponds to a real object in the Study
1789     // as the object may be deleted or modified after the visual state is saved.
1790     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1791     if (!so) continue; //Skip the not existent entry
1792
1793     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1794     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1795
1796     std::vector<std::string>::iterator namesIt = paramNames.begin();
1797     std::vector<std::string>::iterator valuesIt = paramValues.begin();
1798
1799     // actors are stored in a map after displaying of them for
1800     // quicker access in the future: map < viewID to actor >
1801     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
1802     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1803
1804     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1805     {
1806       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1807       // '_' is used as separator and should not be used in viewer type or parameter names.
1808       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
1809       if (lst.size() != 3)
1810         continue;
1811
1812       QString viewerTypStr = lst[0];
1813       QString viewIndexStr = lst[1];
1814       QString paramNameStr = lst[2];
1815
1816       bool ok;
1817       int viewIndex = viewIndexStr.toUInt(&ok);
1818       if (!ok) // bad conversion of view index to integer
1819         continue;
1820
1821       // viewers
1822       if (viewerTypStr == SVTK_Viewer::Type())
1823       {
1824         GEOM_Actor* vActor = 0;
1825         if (vtkActors.IsBound(viewIndex))
1826           vActor = vtkActors.Find(viewIndex);
1827
1828         if (paramNameStr == "Visibility")
1829         {
1830           if (!vActor && displayer())
1831           {
1832             QList<SUIT_ViewManager*> lst;
1833             getApp()->viewManagers(viewerTypStr, lst);
1834
1835             // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1836             if (viewIndex >= 0 && viewIndex < lst.count()) {
1837               SUIT_ViewManager* vman = lst.at(viewIndex);
1838               SUIT_ViewModel* vmodel = vman->getViewModel();
1839               // SVTK view model can be casted to SALOME_View
1840               displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1841
1842               // store displayed actor in a temporary map for quicker
1843               // access later when restoring other parameters
1844               SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1845               vtkRenderer* Renderer = vtkView->getRenderer();
1846               vtkActorCollection* theActors = Renderer->GetActors();
1847               theActors->InitTraversal();
1848               bool isFound = false;
1849               vtkActor *ac = theActors->GetNextActor();
1850               for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
1851                 if (ac->IsA("GEOM_Actor")) {
1852                   GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac);
1853                   if (aGeomAc->hasIO()) {
1854                     Handle(SALOME_InteractiveObject) io =
1855                       Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
1856                     if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1857                       isFound = true;
1858                       vtkActors.Bind(viewIndex, aGeomAc);
1859                     }
1860                   }
1861                 }
1862               }
1863             }
1864           }
1865         } // if (paramNameStr == "Visibility")
1866         else
1867         {
1868           // the rest properties "work" with GEOM_Actor
1869           if (vActor)
1870           {
1871             QString val ((*valuesIt).c_str());
1872
1873             if (paramNameStr == "DisplayMode") {
1874               vActor->setDisplayMode(val.toInt());
1875             }
1876             else if (paramNameStr == "Color") {
1877               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
1878               if (colors.count() == 3)
1879                 vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat());
1880             }
1881             else if (paramNameStr == "Opacity") {
1882               vActor->SetOpacity(val.toFloat());
1883             }
1884             else if (paramNameStr == "Isos") {
1885               QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1886               if (isos.count() == 2) {
1887                 int aIsos[2] = {isos[0].toInt(), isos[1].toInt()};
1888                 vActor->SetNbIsos(aIsos);
1889               }
1890             }
1891           }
1892         } // other parameters than Visibility
1893       }
1894       else if (viewerTypStr == SOCC_Viewer::Type())
1895       {
1896         //Handle(AIS_InteractiveObject) occActor;
1897         Handle(GEOM_AISShape) occActor;
1898         if (occActors.IsBound(viewIndex))
1899           occActor = occActors.Find(viewIndex);
1900
1901         // ViewModel and InteractiveContext
1902         SOCC_Viewer* occVModel = 0;
1903         Handle(AIS_InteractiveContext) ic;
1904
1905         QList<SUIT_ViewManager*> lst;
1906         getApp()->viewManagers(viewerTypStr, lst);
1907
1908         // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager
1909         if (viewIndex >= 0 && viewIndex < lst.count()) {
1910           SUIT_ViewManager* vman = lst.at(viewIndex);
1911           SUIT_ViewModel* vmodel = vman->getViewModel();
1912           occVModel = dynamic_cast<SOCC_Viewer*>(vmodel);
1913           if (occVModel)
1914             ic = occVModel->getAISContext();
1915         }
1916
1917         if (ic.IsNull())
1918           continue;
1919
1920         if (paramNameStr == "Visibility")
1921         {
1922           if (occActor.IsNull() && displayer())
1923           {
1924             displayer()->Display(entry, true, occVModel);
1925
1926             // store displayed actor in a temporary map for quicker
1927             // access later when restoring other parameters
1928             AIS_ListOfInteractive aList;
1929             ic->DisplayedObjects(aList);
1930             bool isFound = false;
1931             AIS_ListIteratorOfListOfInteractive ite (aList);
1932             for (; ite.More() && !isFound; ite.Next()) {
1933               if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1934                 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1935                 if (aSh->hasIO()) {
1936                   Handle(SALOME_InteractiveObject) io =
1937                     Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1938                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1939                     isFound = true;
1940                     occActors.Bind(viewIndex, aSh);
1941                   }
1942                 }
1943               }
1944             }
1945           }
1946         } // if (paramNameStr == "Visibility")
1947         else
1948         {
1949           // the rest properties "work" with GEOM_AISShape
1950           if (!occActor.IsNull())
1951           {
1952             QString val ((*valuesIt).c_str());
1953
1954             if (paramNameStr == "DisplayMode") {
1955               ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false);
1956               //ic->Redisplay(occActor, Standard_False, Standard_True);
1957             }
1958             // Color is restored by the GEOM engine
1959             else if (paramNameStr == "Transparency") {
1960               ic->SetTransparency(occActor, val.toFloat(), false);
1961               ic->Redisplay(occActor, Standard_False, Standard_True);
1962             }
1963             else if (paramNameStr == "Isos") {
1964               QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1965               if (isos.count() == 2) {
1966                 Handle(AIS_Drawer) aDrawer = occActor->Attributes();
1967                 int nbUIso = isos[0].toInt();
1968                 int nbVIso = isos[1].toInt();
1969                 Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect();
1970                 Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect();
1971                 uIsoAspect->SetNumber(nbUIso);
1972                 vIsoAspect->SetNumber(nbVIso);
1973                 aDrawer->SetUIsoAspect(uIsoAspect);
1974                 aDrawer->SetVIsoAspect(vIsoAspect);
1975                 ic->SetLocalAttributes(occActor, aDrawer);
1976                 ic->Redisplay(occActor);
1977               }
1978             }
1979           }
1980         } // other parameters than Visibility
1981       }
1982       else
1983       {
1984         // unknown viewer type
1985       }
1986     } // for names/parameters iterator
1987   } // for entries iterator
1988
1989   // update all VTK and OCC views
1990   QList<SUIT_ViewManager*> lst;
1991   getApp()->viewManagers(lst);
1992   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
1993     SUIT_ViewModel* vmodel = (*it)->getViewModel();
1994     if (!vmodel)
1995       continue;
1996     if (vmodel->getType() == SVTK_Viewer::Type()) {
1997       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
1998       vtkView->getRenderer()->ResetCameraClippingRange();
1999       vtkView->Repaint();
2000     }
2001     else if (vmodel->getType() == SOCC_Viewer::Type()) {
2002       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2003       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
2004       if (occVMod)
2005         occVMod->Repaint();
2006     }
2007   }
2008 }
2009
2010 void GeometryGUI::onViewAboutToShow()
2011 {
2012   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
2013   QAction* a = action( GEOMOp::OpSwitchVectors );
2014   if ( window ) {
2015     a->setEnabled(true);
2016     bool vmode = window->getCustomData("VectorsMode").toBool();
2017     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
2018   } else {
2019     a->setText ( tr("MEN_VECTOR_MODE_ON") );
2020     a->setEnabled(false);
2021   }
2022 }