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