Salome HOME
IMPs 21188, 21053, 21064
[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::EngineComponent_var comp =
176       SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "GEOM" );
177     myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
178   }
179
180   myActiveDialogBox = 0;
181
182   gp_Pnt origin = gp_Pnt(0., 0., 0.);
183   gp_Dir direction = gp_Dir(0., 0., 1.);
184   myWorkingPlane = gp_Ax3(origin, direction);
185
186   myDisplayer = 0;
187   myLocalSelectionMode = GEOM_ALLOBJECTS;
188 }
189
190 //=======================================================================
191 // function : GeometryGUI::~GeometryGUI()
192 // purpose  : Destructor
193 //=======================================================================
194 GeometryGUI::~GeometryGUI()
195 {
196   while (!myOCCSelectors.isEmpty())
197     delete myOCCSelectors.takeFirst();
198
199   while (!myVTKSelectors.isEmpty())
200     delete myVTKSelectors.takeFirst();
201
202   qDeleteAll(myGUIMap);
203 }
204
205 //=======================================================================
206 // function : GeometryGUI::getLibrary()
207 // purpose  : get or load GUI library by name [ internal ]
208 //=======================================================================
209 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
210 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
211 {
212   if ( !myGUIMap.contains( libraryName ) ) {
213     // try to load library if it is not loaded yet
214 #ifndef WNT
215     QString dirs = getenv( "LD_LIBRARY_PATH" );
216     QString sep  = ":";
217 #else
218     QString dirs = getenv( "PATH" );
219     QString sep  = ";";
220 #endif
221     if ( !dirs.isEmpty() ) {
222       QStringList dirList = dirs.split(sep, QString::SkipEmptyParts ); // skip empty entries
223       QListIterator<QString> it( dirList ); it.toBack();
224       while ( it.hasPrevious() ) {
225         QFileInfo fi( Qtx::addSlash( it.previous() ) + libraryName );
226         if ( fi.exists() ) {
227           OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().constData() );
228           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
229           if ( !res ) {
230             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
231             continue; // continue search further
232           }
233           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
234           if ( osdF != NULL ) {
235             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
236             GEOMGUI* libGUI = (*func)( this );
237             if ( libGUI ) {
238               myGUIMap[ libraryName ] = libGUI;
239               break; // found and loaded!
240             }
241           }
242         }
243       }
244     }
245   }
246   return myGUIMap.contains( libraryName ) ? myGUIMap[ libraryName ] : 0;
247 }
248
249 //=======================================================================
250 // function : GeometryGUI::ActiveWorkingPlane()
251 // purpose  : Activate Working Plane View
252 //=======================================================================
253 void GeometryGUI::ActiveWorkingPlane()
254 {
255   gp_Dir DZ = myWorkingPlane.Direction();
256   gp_Dir DY = myWorkingPlane.YDirection();
257
258   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
259   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
260   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
261
262   if( ViewOCC ) {
263     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
264     if ( vw ) {
265       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
266
267       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
268       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
269
270       vw->onViewFitAll();
271     }
272   }
273   else if( ViewVTK ) {
274     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
275     if ( vw ) {
276       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
277
278       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
279       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
280       camera->SetFocalPoint(0,0,0);
281
282       vw->onFitAll();
283     }
284   }
285 }
286
287 //=======================================================================
288 // function : GeometryGUI::SetActiveDialogBox()
289 // purpose  : Set active dialog box
290 //=======================================================================
291 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
292 {
293   myActiveDialogBox = (QDialog*)aDlg;
294 }
295
296 //=======================================================================
297 // function : GeometryGUI::EmitSignalDeactivateDialog()
298 // purpose  : Emit a signal to deactivate the active dialog Box
299 //=======================================================================
300 void GeometryGUI::EmitSignalDeactivateDialog()
301 {
302   emit SignalDeactivateActiveDialog();
303 }
304
305 //=======================================================================
306 // function : GeometryGUI::EmitSignalCloseAllDialogs()
307 // purpose  : Emit a signal to close all non modal dialogs box
308 //=======================================================================
309 void GeometryGUI::EmitSignalCloseAllDialogs()
310 {
311   emit SignalCloseAllDialogs();
312 }
313
314 //=======================================================================
315 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
316 // purpose  : Emit a signal to inform that default real spin box step has
317 //            been changed
318 //=======================================================================
319 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
320 {
321   emit SignalDefaultStepValueChanged(newVal);
322 }
323
324 //=======================================================================
325 // function : GeometryGUI::OnGUIEvent()
326 // purpose  : common slot for all menu/toolbar actions
327 //=======================================================================
328 void GeometryGUI::OnGUIEvent()
329 {
330   const QObject* obj = sender();
331   if ( !obj || !obj->inherits( "QAction" ) )
332     return;
333   int id = actionId((QAction*)obj);
334   if ( id != -1 )
335     OnGUIEvent( id );
336 }
337
338 //=======================================================================
339 // function : GeometryGUI::OnGUIEvent()
340 // purpose  : manage all events on GUI [static]
341 //=======================================================================
342 void GeometryGUI::OnGUIEvent( int id )
343 {
344   SUIT_Application* anApp = application();
345   if (!anApp) return;
346   SUIT_Desktop* desk = anApp->desktop();
347
348   // check type of the active viewframe
349   SUIT_ViewWindow* window = desk->activeWindow();
350   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
351   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
352   // if current viewframe is not of OCC and not of VTK type - return immediately
353   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
354   QList<int> NotViewerDependentCommands;
355   NotViewerDependentCommands << GEOMOp::OpRename
356                              << GEOMOp::OpDelete
357                              << GEOMOp::OpShow
358                              << GEOMOp::OpShowOnly
359                              << GEOMOp::OpShowChildren
360                              << GEOMOp::OpHideChildren
361                              << GEOMOp::OpPointMarker;
362   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
363       return;
364
365   // fix for IPAL9103, point 2
366   if ( CORBA::is_nil( GetGeomGen() ) ) {
367     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
368     return;
369   }
370
371   QString libName;
372   // find corresponding GUI library
373   switch ( id ) {
374   case GEOMOp::OpOriginAndVectors: // MENU BASIC - ORIGIN AND BASE VECTORS
375     createOriginAndBaseVectors(); // internal operation
376     return;
377   case GEOMOp::OpImport:           // MENU FILE - IMPORT
378   case GEOMOp::OpExport:           // MENU FILE - EXPORT
379   case GEOMOp::OpSelectVertex:     // POPUP MENU - SELECT ONLY - VERTEX
380   case GEOMOp::OpSelectEdge:       // POPUP MENU - SELECT ONLY - EDGE
381   case GEOMOp::OpSelectWire:       // POPUP MENU - SELECT ONLY - WIRE
382   case GEOMOp::OpSelectFace:       // POPUP MENU - SELECT ONLY - FACE
383   case GEOMOp::OpSelectShell:      // POPUP MENU - SELECT ONLY - SHELL
384   case GEOMOp::OpSelectSolid:      // POPUP MENU - SELECT ONLY - SOLID
385   case GEOMOp::OpSelectCompound:   // POPUP MENU - SELECT ONLY - COMPOUND
386   case GEOMOp::OpSelectAll:        // POPUP MENU - SELECT ONLY - SELECT ALL
387   case GEOMOp::OpDelete:           // MENU EDIT - DELETE
388   case GEOMOp::OpCheckGeom:        // MENU TOOLS - CHECK GEOMETRY
389   case GEOMOp::OpDeflection:       // POPUP MENU - DEFLECTION COEFFICIENT
390   case GEOMOp::OpColor:            // POPUP MENU - COLOR
391   case GEOMOp::OpTransparency:     // POPUP MENU - TRANSPARENCY
392   case GEOMOp::OpIncrTransparency: // SHORTCUT   - INCREASE TRANSPARENCY
393   case GEOMOp::OpDecrTransparency: // SHORTCUT   - DECREASE TRANSPARENCY
394   case GEOMOp::OpIsos:             // POPUP MENU - ISOS
395   case GEOMOp::OpIncrNbIsos:       // SHORTCUT   - INCREASE NB ISOS
396   case GEOMOp::OpDecrNbIsos:       // SHORTCUT   - DECREASE NB ISOS
397   case GEOMOp::OpAutoColor:        // POPUP MENU - AUTO COLOR
398   case GEOMOp::OpNoAutoColor:      // POPUP MENU - DISABLE AUTO COLOR
399   case GEOMOp::OpShowChildren:     // POPUP MENU - SHOW CHILDREN
400   case GEOMOp::OpHideChildren:     // POPUP MENU - HIDE CHILDREN
401   case GEOMOp::OpPointMarker:      // POPUP MENU - POINT MARKER
402   case GEOMOp::OpRename:           // POPUP MENU - RENAME
403     libName = "GEOMToolsGUI";
404     break;
405   case GEOMOp::OpDisplayMode:      // MENU VIEW - WIREFRAME/SHADING
406   case GEOMOp::OpShowAll:          // MENU VIEW - SHOW ALL
407   case GEOMOp::OpShowOnly:         // MENU VIEW - DISPLAY ONLY
408   case GEOMOp::OpHideAll:          // MENU VIEW - ERASE ALL
409   case GEOMOp::OpHide:             // MENU VIEW - ERASE
410   case GEOMOp::OpShow:             // MENU VIEW - DISPLAY
411   case GEOMOp::OpSwitchVectors:    // MENU VIEW - VECTOR MODE
412   case GEOMOp::OpWireframe:        // POPUP MENU - WIREFRAME
413   case GEOMOp::OpShading:          // POPUP MENU - SHADING
414   case GEOMOp::OpVectors:          // POPUP MENU - VECTORS
415     libName = "DisplayGUI";
416     break;
417   case GEOMOp::OpPoint:            // MENU BASIC - POINT
418   case GEOMOp::OpLine:             // MENU BASIC - LINE
419   case GEOMOp::OpCircle:           // MENU BASIC - CIRCLE
420   case GEOMOp::OpEllipse:          // MENU BASIC - ELLIPSE
421   case GEOMOp::OpArc:              // MENU BASIC - ARC
422   case GEOMOp::OpVector:           // MENU BASIC - VECTOR
423   case GEOMOp::OpPlane:            // MENU BASIC - PLANE
424   case GEOMOp::OpCurve:            // MENU BASIC - CURVE
425   case GEOMOp::OpLCS:              // MENU BASIC - LOCAL COORDINATE SYSTEM
426     libName = "BasicGUI";
427     break;
428   case GEOMOp::OpBox:              // MENU PRIMITIVE - BOX
429   case GEOMOp::OpCylinder:         // MENU PRIMITIVE - CYLINDER
430   case GEOMOp::OpSphere:           // MENU PRIMITIVE - SPHERE
431   case GEOMOp::OpTorus:            // MENU PRIMITIVE - TORUS
432   case GEOMOp::OpCone:             // MENU PRIMITIVE - CONE
433   case GEOMOp::OpRectangle:        // MENU PRIMITIVE - FACE
434   case GEOMOp::OpDisk:             // MENU PRIMITIVE - DISK
435     libName = "PrimitiveGUI";
436     break;
437   case GEOMOp::OpPrism:            // MENU GENERATION - PRISM
438   case GEOMOp::OpRevolution:       // MENU GENERATION - REVOLUTION
439   case GEOMOp::OpFilling:          // MENU GENERATION - FILLING
440   case GEOMOp::OpPipe:             // MENU GENERATION - PIPE
441     libName = "GenerationGUI";
442     break;
443   case GEOMOp::Op2dSketcher:       // MENU ENTITY - SKETCHER
444   case GEOMOp::Op3dSketcher:       // MENU ENTITY - 3D SKETCHER
445   case GEOMOp::OpExplode:          // MENU ENTITY - EXPLODE
446     libName = "EntityGUI";
447     break;
448   case GEOMOp::OpEdge:             // MENU BUILD - EDGE
449   case GEOMOp::OpWire:             // MENU BUILD - WIRE
450   case GEOMOp::OpFace:             // MENU BUILD - FACE
451   case GEOMOp::OpShell:            // MENU BUILD - SHELL
452   case GEOMOp::OpSolid:            // MENU BUILD - SOLID
453   case GEOMOp::OpCompound:         // MENU BUILD - COMPUND
454     libName = "BuildGUI";
455     break;
456   case GEOMOp::OpFuse:             // MENU BOOLEAN - FUSE
457   case GEOMOp::OpCommon:           // MENU BOOLEAN - COMMON
458   case GEOMOp::OpCut:              // MENU BOOLEAN - CUT
459   case GEOMOp::OpSection:          // MENU BOOLEAN - SECTION
460     libName = "BooleanGUI";
461     break;
462   case GEOMOp::OpTranslate:        // MENU TRANSFORMATION - TRANSLATION
463   case GEOMOp::OpRotate:           // MENU TRANSFORMATION - ROTATION
464   case GEOMOp::OpChangeLoc:        // MENU TRANSFORMATION - LOCATION
465   case GEOMOp::OpMirror:           // MENU TRANSFORMATION - MIRROR
466   case GEOMOp::OpScale:            // MENU TRANSFORMATION - SCALE
467   case GEOMOp::OpOffset:           // MENU TRANSFORMATION - OFFSET
468   case GEOMOp::OpMultiTranslate:   // MENU TRANSFORMATION - MULTI-TRANSLATION
469   case GEOMOp::OpMultiRotate:      // MENU TRANSFORMATION - MULTI-ROTATION
470   case GEOMOp::OpReimport:         // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
471     libName = "TransformationGUI";
472     break;
473   case GEOMOp::OpPartition:        // MENU OPERATION - PARTITION
474   case GEOMOp::OpArchimede:        // MENU OPERATION - ARCHIMEDE
475   case GEOMOp::OpFillet3d:         // MENU OPERATION - FILLET
476   case GEOMOp::OpChamfer:          // MENU OPERATION - CHAMFER
477   case GEOMOp::OpClipping:         // MENU OPERATION - CLIPPING RANGE
478   case GEOMOp::OpShapesOnShape:    // MENU OPERATION - GET SHAPES ON SHAPE
479   case GEOMOp::OpFillet2d:         // MENU OPERATION - FILLET 2D
480   case GEOMOp::OpFillet1d:         // MENU OPERATION - FILLET 1D
481   case GEOMOp::OpSharedShapes:     // MENU OPERATION - GET SHARED SHAPES
482     libName = "OperationGUI";
483     break;
484   case GEOMOp::OpSewing:           // MENU REPAIR - SEWING
485   case GEOMOp::OpSuppressFaces:    // MENU REPAIR - SUPPRESS FACES
486   case GEOMOp::OpSuppressHoles:    // MENU REPAIR - SUPPRESS HOLE
487   case GEOMOp::OpShapeProcess:     // MENU REPAIR - SHAPE PROCESSING
488   case GEOMOp::OpCloseContour:     // MENU REPAIR - CLOSE CONTOUR
489   case GEOMOp::OpRemoveIntWires:   // MENU REPAIR - REMOVE INTERNAL WIRES
490   case GEOMOp::OpAddPointOnEdge:   // MENU REPAIR - ADD POINT ON EDGE
491   case GEOMOp::OpFreeBoundaries:   // MENU MEASURE - FREE BOUNDARIES
492   case GEOMOp::OpFreeFaces:        // MENU MEASURE - FREE FACES
493   case GEOMOp::OpOrientation:      // MENU REPAIR - CHANGE ORIENTATION
494   case GEOMOp::OpGlueFaces:        // MENU REPAIR - GLUE FACES
495   case GEOMOp::OpLimitTolerance:   // MENU REPAIR - LIMIT TOLERANCE
496   case GEOMOp::OpRemoveExtraEdges: // MENU REPAIR - REMOVE EXTRA EDGES
497     libName = "RepairGUI";
498     break;
499   case GEOMOp::OpProperties:       // MENU MEASURE - PROPERTIES
500   case GEOMOp::OpCenterMass:       // MENU MEASURE - CDG
501   case GEOMOp::OpInertia:          // MENU MEASURE - INERTIA
502   case GEOMOp::OpNormale:          // MENU MEASURE - NORMALE
503   case GEOMOp::OpBoundingBox:      // MENU MEASURE - BOUNDING BOX
504   case GEOMOp::OpMinDistance:      // MENU MEASURE - MIN DISTANCE
505   case GEOMOp::OpAngle:            // MENU MEASURE - ANGLE
506   case GEOMOp::OpTolerance:        // MENU MEASURE - TOLERANCE
507   case GEOMOp::OpWhatIs:           // MENU MEASURE - WHATIS
508   case GEOMOp::OpCheckShape:       // MENU MEASURE - CHECK
509   case GEOMOp::OpCheckCompound:    // MENU MEASURE - CHECK COMPOUND OF BLOCKS
510   case GEOMOp::OpPointCoordinates: // MENU MEASURE - POINT COORDINATES
511     libName = "MeasureGUI";
512     break;
513   case GEOMOp::OpGroupCreate:      // MENU GROUP - CREATE
514   case GEOMOp::OpGroupCreatePopup: // POPUP MENU - CREATE GROUP
515   case GEOMOp::OpGroupEdit:        // MENU GROUP - EDIT
516     libName = "GroupGUI";
517     break;
518   case GEOMOp::OpHexaSolid:        // MENU BLOCKS - HEXAHEDRAL SOLID
519   case GEOMOp::OpMultiTransform:   // MENU BLOCKS - MULTI-TRANSFORMATION
520   case GEOMOp::OpQuadFace:         // MENU BLOCKS - QUADRANGLE FACE
521   case GEOMOp::OpPropagate:        // MENU BLOCKS - PROPAGATE
522   case GEOMOp::OpExplodeBlock:     // MENU BLOCKS - EXPLODE ON BLOCKS
523     libName = "BlocksGUI";
524     break;
525   case GEOMOp::OpAdvancedNoOp:     // NO OPERATION (advanced operations base)
526   case GEOMOp::OpPipeTShape:       // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE
527 //   case GEOMOp::OpPipeTShapeGroups:     // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE GROUPS
528     //@@ 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 @@//
529     libName = "AdvancedGUI";
530     break;
531   default:
532     break;
533   }
534
535   GEOMGUI* library = 0;
536   if ( !libName.isEmpty() ) {
537 #ifndef WNT
538     libName = QString( "lib" ) + libName + ".so";
539 #else
540     libName = libName + ".dll";
541 #endif
542     library = getLibrary( libName );
543   }
544
545   // call method of corresponding GUI library
546   if ( library )
547     library->OnGUIEvent( id, desk );
548   else
549     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
550 }
551
552 //=================================================================================
553 // function : GeometryGUI::OnKeyPress()
554 // purpose  : Called when any key is pressed by user [static]
555 //=================================================================================
556 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* w, QKeyEvent* e )
557 {
558   if ( !application() )
559     return;
560   foreach ( GEOMGUI* lib, myGUIMap )
561     lib->OnKeyPress( e, application()->desktop(), w );
562 }
563
564 //=================================================================================
565 // function : GeometryGUI::OnMouseMove()
566 // purpose  : Manages mouse move events [static]
567 //=================================================================================
568 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* w, QMouseEvent* e )
569 {
570   if ( !application() )
571     return;
572   foreach ( GEOMGUI* lib, myGUIMap )
573     lib->OnMouseMove( e, application()->desktop(), w );
574 }
575
576 //=================================================================================
577 // function : GeometryGUI::OnMousePress()
578 // purpose  : Manage mouse press events [static]
579 //=================================================================================
580 void GeometryGUI::OnMousePress( SUIT_ViewWindow* w, QMouseEvent* e )
581 {
582   if ( !application() )
583     return;
584   foreach ( GEOMGUI* lib, myGUIMap )
585     lib->OnMousePress( e, application()->desktop(), w );
586 }
587
588 //=======================================================================
589 // function : createGeomAction
590 // purpose  :
591 //=======================================================================
592 void GeometryGUI::createGeomAction( const int id, const QString& label, const QString& icolabel,
593                                     const int accel, const bool toggle, const QString& shortcutAction )
594 {
595   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
596   QPixmap icon = icolabel.isEmpty() ? resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+label).toLatin1().constData() ), false )
597                                     : resMgr->loadPixmap( "GEOM", tr( icolabel.toLatin1().constData() ) );
598   createAction( id,
599                 tr( QString( "TOP_%1" ).arg( label ).toLatin1().constData() ),
600                 icon,
601                 tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ),
602                 tr( QString( "STB_%1" ).arg( label ).toLatin1().constData() ),
603                 accel,
604                 application()->desktop(),
605                 toggle,
606                 this, SLOT( OnGUIEvent() ),
607                 shortcutAction );
608 }
609
610 //=======================================================================
611 // function : createOriginAndBaseVectors
612 // purpose  :
613 //=======================================================================
614 void GeometryGUI::createOriginAndBaseVectors()
615 {
616   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
617   if( appStudy ) {
618     _PTR(Study) studyDS = appStudy->studyDS();
619     if( studyDS && !CORBA::is_nil( GetGeomGen() ) ) {
620       GEOM::GEOM_IBasicOperations_var aBasicOperations = GetGeomGen()->GetIBasicOperations( studyDS->StudyId() );
621       if( !aBasicOperations->_is_nil() ) {
622         SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
623         double aLength = aResourceMgr->doubleValue( "Geometry", "base_vectors_length", 1.0 );
624         GEOM::GEOM_Object_var anOrigin = aBasicOperations->MakePointXYZ( 0.0, 0.0, 0.0 );
625         GEOM::GEOM_Object_var anOX = aBasicOperations->MakeVectorDXDYDZ( aLength, 0.0, 0.0 );
626         GEOM::GEOM_Object_var anOY = aBasicOperations->MakeVectorDXDYDZ( 0.0, aLength, 0.0 );
627         GEOM::GEOM_Object_var anOZ = aBasicOperations->MakeVectorDXDYDZ( 0.0, 0.0, aLength );
628
629         SALOMEDS::Study_var aDSStudy = ClientStudyToStudy( studyDS );
630         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOrigin, "O" );
631         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOX, "OX" );
632         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOY, "OY" );
633         GetGeomGen()->PublishInStudy( aDSStudy, SALOMEDS::SObject::_nil(), anOZ, "OZ" );
634
635         getApp()->updateObjectBrowser( false );
636       }
637     }
638   }
639 }
640
641 //=======================================================================
642 // function : GeometryGUI::initialize()
643 // purpose  : Called when GEOM module is created
644 //=======================================================================
645 void GeometryGUI::initialize( CAM_Application* app )
646 {
647   SalomeApp_Module::initialize( app );
648
649   // ----- create actions --------------
650
651   createGeomAction( GEOMOp::OpImport,     "IMPORT", "", Qt::ControlModifier + Qt::Key_I );
652   createGeomAction( GEOMOp::OpExport,     "EXPORT", "", Qt::ControlModifier + Qt::Key_E );
653
654   createGeomAction( GEOMOp::OpDelete,     "DELETE", "", Qt::Key_Delete );
655
656   createGeomAction( GEOMOp::OpPoint,      "POINT" );
657   createGeomAction( GEOMOp::OpLine,       "LINE" );
658   createGeomAction( GEOMOp::OpCircle,     "CIRCLE" );
659   createGeomAction( GEOMOp::OpEllipse,    "ELLIPSE" );
660   createGeomAction( GEOMOp::OpArc,        "ARC" );
661   createGeomAction( GEOMOp::OpCurve,      "CURVE" );
662   createGeomAction( GEOMOp::OpVector,     "VECTOR" );
663   createGeomAction( GEOMOp::OpPlane,      "PLANE" );
664   createGeomAction( GEOMOp::OpLCS,        "LOCAL_CS" );
665   createGeomAction( GEOMOp::OpOriginAndVectors, "ORIGIN_AND_VECTORS" );
666
667   createGeomAction( GEOMOp::OpBox,        "BOX" );
668   createGeomAction( GEOMOp::OpCylinder,   "CYLINDER" );
669   createGeomAction( GEOMOp::OpSphere,     "SPHERE" );
670   createGeomAction( GEOMOp::OpTorus,      "TORUS" );
671   createGeomAction( GEOMOp::OpCone,       "CONE" );
672   createGeomAction( GEOMOp::OpRectangle,  "RECTANGLE" );
673   createGeomAction( GEOMOp::OpDisk,       "DISK" );
674
675   createGeomAction( GEOMOp::OpPrism,       "EXTRUSION" );
676   createGeomAction( GEOMOp::OpRevolution,  "REVOLUTION" );
677   createGeomAction( GEOMOp::OpFilling,     "FILLING" );
678   createGeomAction( GEOMOp::OpPipe,        "PIPE" );
679
680   createGeomAction( GEOMOp::OpGroupCreate, "GROUP_CREATE" );
681   createGeomAction( GEOMOp::OpGroupEdit,   "GROUP_EDIT" );
682
683   createGeomAction( GEOMOp::OpReimport,    "RELOAD_IMPORTED" );
684
685   createGeomAction( GEOMOp::OpQuadFace,    "Q_FACE" );
686   createGeomAction( GEOMOp::OpHexaSolid,   "HEX_SOLID" );
687
688   createGeomAction( GEOMOp::Op2dSketcher,  "SKETCH" );
689   createGeomAction( GEOMOp::Op3dSketcher,  "3DSKETCH" );
690   createGeomAction( GEOMOp::OpExplode,     "EXPLODE" );
691
692   createGeomAction( GEOMOp::OpEdge,        "EDGE" );
693   createGeomAction( GEOMOp::OpWire,        "WIRE" );
694   createGeomAction( GEOMOp::OpFace,        "FACE" );
695   createGeomAction( GEOMOp::OpShell,       "SHELL" );
696   createGeomAction( GEOMOp::OpSolid,       "SOLID" );
697   createGeomAction( GEOMOp::OpCompound,    "COMPOUND" );
698
699   createGeomAction( GEOMOp::OpFuse,        "FUSE" );
700   createGeomAction( GEOMOp::OpCommon,      "COMMON" );
701   createGeomAction( GEOMOp::OpCut,         "CUT" );
702   createGeomAction( GEOMOp::OpSection,     "SECTION" );
703
704   createGeomAction( GEOMOp::OpTranslate,      "TRANSLATION" );
705   createGeomAction( GEOMOp::OpRotate,         "ROTATION" );
706   createGeomAction( GEOMOp::OpChangeLoc,      "MODIFY_LOCATION" );
707   createGeomAction( GEOMOp::OpMirror,         "MIRROR" );
708   createGeomAction( GEOMOp::OpScale,          "SCALE" );
709   createGeomAction( GEOMOp::OpOffset,         "OFFSET" );
710   createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" );
711   createGeomAction( GEOMOp::OpMultiRotate,    "MUL_ROTATION" );
712
713   createGeomAction( GEOMOp::OpPartition,      "PARTITION" );
714   createGeomAction( GEOMOp::OpArchimede,      "ARCHIMEDE" );
715   createGeomAction( GEOMOp::OpFillet3d,       "FILLET" );
716   createGeomAction( GEOMOp::OpChamfer,        "CHAMFER" );
717   //createGeomAction( GEOMOp::OpClipping,        "CLIPPING" );
718   createGeomAction( GEOMOp::OpShapesOnShape,  "GET_SHAPES_ON_SHAPE" );
719   createGeomAction( GEOMOp::OpSharedShapes,   "GET_SHARED_SHAPES" );
720   createGeomAction( GEOMOp::OpFillet1d,       "FILLET_1D" );
721   createGeomAction( GEOMOp::OpFillet2d,       "FILLET_2D" );
722
723   createGeomAction( GEOMOp::OpMultiTransform, "MUL_TRANSFORM" );
724   createGeomAction( GEOMOp::OpExplodeBlock,   "EXPLODE_BLOCKS" );
725   createGeomAction( GEOMOp::OpPropagate,      "PROPAGATE" );
726
727   createGeomAction( GEOMOp::OpSewing,           "SEWING" );
728   createGeomAction( GEOMOp::OpGlueFaces,        "GLUE_FACES" );
729   createGeomAction( GEOMOp::OpLimitTolerance,   "LIMIT_TOLERANCE" );
730   createGeomAction( GEOMOp::OpSuppressFaces,    "SUPPRESS_FACES" );
731   createGeomAction( GEOMOp::OpSuppressHoles,    "SUPPERSS_HOLES" );
732   createGeomAction( GEOMOp::OpShapeProcess,     "SHAPE_PROCESS" );
733   createGeomAction( GEOMOp::OpCloseContour,     "CLOSE_CONTOUR" );
734   createGeomAction( GEOMOp::OpRemoveIntWires,   "SUPPRESS_INT_WIRES" );
735   createGeomAction( GEOMOp::OpAddPointOnEdge,   "POINT_ON_EDGE" );
736   createGeomAction( GEOMOp::OpFreeBoundaries,   "CHECK_FREE_BNDS" );
737   createGeomAction( GEOMOp::OpFreeFaces,        "CHECK_FREE_FACES" );
738   createGeomAction( GEOMOp::OpOrientation,      "CHANGE_ORIENTATION" );
739   createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" );
740
741   createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" );
742   createGeomAction( GEOMOp::OpProperties,       "BASIC_PROPS" );
743   createGeomAction( GEOMOp::OpCenterMass,       "MASS_CENTER" );
744   createGeomAction( GEOMOp::OpInertia,          "INERTIA" );
745   createGeomAction( GEOMOp::OpNormale,          "NORMALE" );
746   createGeomAction( GEOMOp::OpBoundingBox,      "BND_BOX" );
747   createGeomAction( GEOMOp::OpMinDistance,      "MIN_DIST" );
748   createGeomAction( GEOMOp::OpAngle,            "MEASURE_ANGLE" );
749
750   createGeomAction( GEOMOp::OpTolerance,        "TOLERANCE" );
751   createGeomAction( GEOMOp::OpWhatIs,           "WHAT_IS" );
752   createGeomAction( GEOMOp::OpCheckShape,       "CHECK" );
753   createGeomAction( GEOMOp::OpCheckCompound,    "CHECK_COMPOUND" );
754
755 #ifdef _DEBUG_ // PAL16821
756   createGeomAction( GEOMOp::OpCheckGeom,        "CHECK_GEOMETRY" );
757 #endif
758
759   createGeomAction( GEOMOp::OpDisplayMode,      "SHADING" );
760   createGeomAction( GEOMOp::OpShowAll,          "DISPLAY_ALL" );
761   createGeomAction( GEOMOp::OpHideAll,          "ERASE_ALL" );
762   createGeomAction( GEOMOp::OpShow,             "DISPLAY" );
763   createGeomAction( GEOMOp::OpSwitchVectors,    "VECTOR_MODE");
764   createGeomAction( GEOMOp::OpSelectVertex,     "VERTEX_SEL_ONLY" ,"", 0, true );
765   createGeomAction( GEOMOp::OpSelectEdge,       "EDGE_SEL_ONLY", "", 0, true );
766   createGeomAction( GEOMOp::OpSelectWire,       "WIRE_SEL_ONLY", "",  0, true );
767   createGeomAction( GEOMOp::OpSelectFace,       "FACE_SEL_ONLY", "", 0, true );
768   createGeomAction( GEOMOp::OpSelectShell,      "SHELL_SEL_ONLY", "",  0, true );
769   createGeomAction( GEOMOp::OpSelectSolid,      "SOLID_SEL_ONLY", "", 0, true );
770   createGeomAction( GEOMOp::OpSelectCompound,   "COMPOUND_SEL_ONLY", "",  0, true );
771   createGeomAction( GEOMOp::OpSelectAll,        "ALL_SEL_ONLY", "",  0, true );
772   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
773   createGeomAction( GEOMOp::OpHide,             "ERASE" );
774
775   createGeomAction( GEOMOp::OpRename,           "POP_RENAME", "", Qt::Key_F2 );
776   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
777   createGeomAction( GEOMOp::OpShading,          "POP_SHADING", "", 0, true );
778   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
779   createGeomAction( GEOMOp::OpDeflection,       "POP_DEFLECTION" );
780   createGeomAction( GEOMOp::OpColor,            "POP_COLOR" );
781   createGeomAction( GEOMOp::OpTransparency,     "POP_TRANSPARENCY" );
782   createGeomAction( GEOMOp::OpIsos,             "POP_ISOS" );
783   createGeomAction( GEOMOp::OpAutoColor,        "POP_AUTO_COLOR" );
784   createGeomAction( GEOMOp::OpNoAutoColor,      "POP_DISABLE_AUTO_COLOR" );
785   createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
786   createGeomAction( GEOMOp::OpShowChildren,     "POP_SHOW_CHILDREN" );
787   createGeomAction( GEOMOp::OpHideChildren,     "POP_HIDE_CHILDREN" );
788   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
789
790   createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
791
792   // Create actions for increase/decrease transparency shortcuts
793   createGeomAction( GEOMOp::OpIncrTransparency, "", "", 0, false,
794                     "Geometry:Increase transparency");
795   createGeomAction( GEOMOp::OpDecrTransparency, "", "", 0, false,
796                     "Geometry:Decrease transparency");
797
798   // Create actions for increase/decrease number of isolines
799   createGeomAction( GEOMOp::OpIncrNbIsos, "", "", 0, false,
800                     "Geometry:Increase number of isolines");
801   createGeomAction( GEOMOp::OpDecrNbIsos, "", "", 0, false,
802                     "Geometry:Decrease number of isolines");
803
804 //   createGeomAction( GEOMOp::OpPipeTShapeGroups, "PIPETSHAPEGROUPS" );
805   //@@ 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 @@//
806
807   // ---- create menus --------------------------
808
809   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
810   createMenu( separator(),      fileId, 10 );
811   createMenu( GEOMOp::OpImport, fileId, 10 );
812   createMenu( GEOMOp::OpExport, fileId, 10 );
813   createMenu( separator(),      fileId, -1 );
814
815   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
816   createMenu( GEOMOp::OpDelete, editId, -1 );
817
818   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
819
820   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
821   createMenu( GEOMOp::OpPoint,   basicId, -1 );
822   createMenu( GEOMOp::OpLine,    basicId, -1 );
823   createMenu( GEOMOp::OpCircle,  basicId, -1 );
824   createMenu( GEOMOp::OpEllipse, basicId, -1 );
825   createMenu( GEOMOp::OpArc,     basicId, -1 );
826   createMenu( GEOMOp::OpCurve,   basicId, -1 );
827   createMenu( separator(),       basicId, -1 );
828   createMenu( GEOMOp::OpVector,  basicId, -1 );
829   createMenu( GEOMOp::OpPlane,   basicId, -1 );
830   createMenu( GEOMOp::OpLCS,     basicId, -1 );
831   createMenu( GEOMOp::OpOriginAndVectors, basicId, -1 );
832
833   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
834   createMenu( GEOMOp::OpBox,       primId, -1 );
835   createMenu( GEOMOp::OpCylinder,  primId, -1 );
836   createMenu( GEOMOp::OpSphere,    primId, -1 );
837   createMenu( GEOMOp::OpTorus,     primId, -1 );
838   createMenu( GEOMOp::OpCone,      primId, -1 );
839   createMenu( GEOMOp::OpRectangle, primId, -1 );
840   createMenu( GEOMOp::OpDisk,      primId, -1 );
841
842   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
843   createMenu( GEOMOp::OpPrism,      genId, -1 );
844   createMenu( GEOMOp::OpRevolution, genId, -1 );
845   createMenu( GEOMOp::OpFilling,    genId, -1 );
846   createMenu( GEOMOp::OpPipe,       genId, -1 );
847
848   int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
849   createMenu( GEOMOp::OpPipeTShape, advId, -1 );
850 //   createMenu( GEOMOp::OpPipeTShapeGroups, advId, -1 );
851   //@@ 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 @@//
852
853   createMenu( separator(), newEntId, -1 );
854
855   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
856   createMenu( GEOMOp::OpGroupCreate, groupId, -1 );
857   createMenu( GEOMOp::OpGroupEdit,   groupId, -1 );
858
859   createMenu( separator(), newEntId, -1 );
860
861   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
862   createMenu( GEOMOp::OpQuadFace,  blocksId, -1 );
863   createMenu( GEOMOp::OpHexaSolid, blocksId, -1 );
864
865   createMenu( separator(),          newEntId, -1 );
866
867   createMenu( GEOMOp::Op2dSketcher, newEntId, -1 );
868   createMenu( GEOMOp::Op3dSketcher, newEntId, -1 );
869
870   createMenu( separator(),          newEntId, -1 );
871
872   createMenu( GEOMOp::OpExplode,    newEntId, -1 );
873
874   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
875   createMenu( GEOMOp::OpEdge,     buildId, -1 );
876   createMenu( GEOMOp::OpWire,     buildId, -1 );
877   createMenu( GEOMOp::OpFace,     buildId, -1 );
878   createMenu( GEOMOp::OpShell,    buildId, -1 );
879   createMenu( GEOMOp::OpSolid,    buildId, -1 );
880   createMenu( GEOMOp::OpCompound, buildId, -1 );
881
882   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
883
884   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
885   createMenu( GEOMOp::OpFuse,    boolId, -1 );
886   createMenu( GEOMOp::OpCommon,  boolId, -1 );
887   createMenu( GEOMOp::OpCut,     boolId, -1 );
888   createMenu( GEOMOp::OpSection, boolId, -1 );
889
890   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
891   createMenu( GEOMOp::OpTranslate,      transId, -1 );
892   createMenu( GEOMOp::OpRotate,         transId, -1 );
893   createMenu( GEOMOp::OpChangeLoc,      transId, -1 );
894   createMenu( GEOMOp::OpMirror,         transId, -1 );
895   createMenu( GEOMOp::OpScale,          transId, -1 );
896   createMenu( GEOMOp::OpOffset,         transId, -1 );
897   createMenu( separator(),              transId, -1 );
898   createMenu( GEOMOp::OpMultiTranslate, transId, -1 );
899   createMenu( GEOMOp::OpMultiRotate,    transId, -1 );
900
901   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
902   createMenu( GEOMOp::OpMultiTransform, blockId, -1 );
903   createMenu( GEOMOp::OpExplodeBlock,   blockId, -1 );
904   createMenu( GEOMOp::OpPropagate,      blockId, -1 );
905
906   createMenu( separator(), operId, -1 );
907
908   createMenu( GEOMOp::OpPartition,     operId, -1 );
909   createMenu( GEOMOp::OpArchimede,     operId, -1 );
910   createMenu( GEOMOp::OpShapesOnShape, operId, -1 );
911   createMenu( GEOMOp::OpSharedShapes,  operId, -1 );
912
913   createMenu( separator(), operId, -1 );
914
915   createMenu( GEOMOp::OpFillet1d,      operId, -1 );
916   createMenu( GEOMOp::OpFillet2d,      operId, -1 );
917   createMenu( GEOMOp::OpFillet3d,      operId, -1 );
918   createMenu( GEOMOp::OpChamfer,       operId, -1 );
919   //createMenu( GEOMOp::OpClipping,      operId, -1 );
920
921   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
922   createMenu( GEOMOp::OpShapeProcess,    repairId, -1 );
923   createMenu( GEOMOp::OpSuppressFaces,   repairId, -1 );
924   createMenu( GEOMOp::OpCloseContour,    repairId, -1 );
925   createMenu( GEOMOp::OpRemoveIntWires,  repairId, -1 );
926   createMenu( GEOMOp::OpSuppressHoles,   repairId, -1 );
927   createMenu( GEOMOp::OpSewing,          repairId, -1 );
928   createMenu( GEOMOp::OpGlueFaces,       repairId, -1 );
929   createMenu( GEOMOp::OpLimitTolerance,  repairId, -1 );
930   createMenu( GEOMOp::OpAddPointOnEdge,  repairId, -1 );
931   //createMenu( GEOMOp::OpFreeBoundaries,  repairId, -1 );
932   //createMenu( GEOMOp::OpFreeFaces,       repairId, -1 );
933   createMenu( GEOMOp::OpOrientation,      repairId, -1 );
934   createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 );
935
936   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
937   createMenu( GEOMOp::OpPointCoordinates, measurId, -1 );
938   createMenu( GEOMOp::OpProperties,       measurId, -1 );
939   createMenu( separator(),                measurId, -1 );
940   createMenu( GEOMOp::OpCenterMass,       measurId, -1 );
941   createMenu( GEOMOp::OpInertia,          measurId, -1 );
942   createMenu( GEOMOp::OpNormale,          measurId, -1 );
943   createMenu( separator(),                measurId, -1 );
944   createMenu( GEOMOp::OpFreeBoundaries,   measurId, -1 );
945   createMenu( GEOMOp::OpFreeFaces,        measurId, -1 );
946   createMenu( separator(),                measurId, -1 );
947
948   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
949   createMenu( GEOMOp::OpBoundingBox, dimId, -1 );
950   createMenu( GEOMOp::OpMinDistance, dimId, -1 );
951   createMenu( GEOMOp::OpAngle,       dimId, -1 );
952
953   createMenu( separator(),             measurId, -1 );
954   createMenu( GEOMOp::OpTolerance,     measurId, -1 );
955   createMenu( separator(),             measurId, -1 );
956   createMenu( GEOMOp::OpWhatIs,        measurId, -1 );
957   createMenu( GEOMOp::OpCheckShape,    measurId, -1 );
958   createMenu( GEOMOp::OpCheckCompound, measurId, -1 );
959
960 #ifdef _DEBUG_ // PAL16821
961   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
962   createMenu( separator(),         toolsId, -1 );
963   createMenu( GEOMOp::OpCheckGeom, toolsId, -1 );
964 #endif
965
966   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
967   createMenu( separator(),       viewId, -1 );
968
969   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
970   createMenu( GEOMOp::OpDisplayMode,   dispmodeId, -1 );
971   createMenu( separator(),             dispmodeId, -1 );
972   createMenu( GEOMOp::OpSwitchVectors, dispmodeId, -1 );
973
974   createMenu( separator(),       viewId, -1 );
975   createMenu( GEOMOp::OpShowAll, viewId, -1 );
976   createMenu( GEOMOp::OpHideAll, viewId, -1 );
977   createMenu( separator(),       viewId, -1 );
978
979 /*
980   PAL9111:
981   because of these items are accessible through object browser and viewers
982   we have removed they from main menu
983
984   createMenu( GEOMOp::OpShow, viewId, -1 );
985   createMenu( GEOMOp::OpShowOnly, viewId, -1 );
986   createMenu( GEOMOp::OpHide, viewId, -1 );
987 */
988
989   // ---- create toolbars --------------------------
990
991   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
992   createTool( GEOMOp::OpPoint,   basicTbId );
993   createTool( GEOMOp::OpLine,    basicTbId );
994   createTool( GEOMOp::OpCircle,  basicTbId );
995   createTool( GEOMOp::OpEllipse, basicTbId );
996   createTool( GEOMOp::OpArc,     basicTbId );
997   createTool( GEOMOp::OpCurve,   basicTbId );
998   createTool( GEOMOp::OpVector,  basicTbId );
999   createTool( GEOMOp::OpPlane,   basicTbId );
1000   createTool( GEOMOp::OpLCS,     basicTbId );
1001   createTool( GEOMOp::OpOriginAndVectors, basicTbId );
1002
1003   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1004   createTool( GEOMOp::OpBox,       primTbId );
1005   createTool( GEOMOp::OpCylinder,  primTbId );
1006   createTool( GEOMOp::OpSphere,    primTbId );
1007   createTool( GEOMOp::OpTorus,     primTbId );
1008   createTool( GEOMOp::OpCone,      primTbId );
1009   createTool( GEOMOp::OpRectangle, primTbId );
1010   createTool( GEOMOp::OpDisk,      primTbId );
1011
1012   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1013   createTool( GEOMOp::OpFuse,    boolTbId );
1014   createTool( GEOMOp::OpCommon,  boolTbId );
1015   createTool( GEOMOp::OpCut,     boolTbId );
1016   createTool( GEOMOp::OpSection, boolTbId );
1017
1018   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1019   createTool( GEOMOp::OpPrism,      genTbId );
1020   createTool( GEOMOp::OpRevolution, genTbId );
1021   createTool( GEOMOp::OpFilling,    genTbId );
1022   createTool( GEOMOp::OpPipe,       genTbId );
1023
1024   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1025   createTool( GEOMOp::OpTranslate,      transTbId );
1026   createTool( GEOMOp::OpRotate,         transTbId );
1027   createTool( GEOMOp::OpChangeLoc,      transTbId );
1028   createTool( GEOMOp::OpMirror,         transTbId );
1029   createTool( GEOMOp::OpScale,          transTbId );
1030   createTool( GEOMOp::OpOffset,         transTbId );
1031   createTool( separator(),              transTbId );
1032   createTool( GEOMOp::OpMultiTranslate, transTbId );
1033   createTool( GEOMOp::OpMultiRotate,    transTbId );
1034
1035   int operTbId = createTool( tr( "TOOL_OPERATIONS" ) );
1036   createTool( GEOMOp::Op2dSketcher,      operTbId );
1037   createTool( GEOMOp::Op3dSketcher,      operTbId );
1038   createTool( separator(),               operTbId );
1039   createTool( GEOMOp::OpExplode,         operTbId );
1040   createTool( separator(),               operTbId );
1041   createTool( GEOMOp::OpPartition,       operTbId );
1042   createTool( GEOMOp::OpArchimede,       operTbId );
1043   createTool( GEOMOp::OpShapesOnShape,   operTbId );
1044   createTool( GEOMOp::OpSharedShapes,    operTbId );
1045   createTool( separator(),               operTbId );
1046   createTool( GEOMOp::OpFillet1d,        operTbId );
1047   createTool( GEOMOp::OpFillet2d,        operTbId );
1048   createTool( GEOMOp::OpFillet3d,        operTbId );
1049   createTool( GEOMOp::OpChamfer,         operTbId );
1050
1051   int buildTbId = createTool( tr( "TOOL_BUILD" ) );
1052   createTool( GEOMOp::OpEdge,     buildTbId );
1053   createTool( GEOMOp::OpWire,     buildTbId );
1054   createTool( GEOMOp::OpFace,     buildTbId );
1055   createTool( GEOMOp::OpShell,    buildTbId );
1056   createTool( GEOMOp::OpSolid,    buildTbId );
1057   createTool( GEOMOp::OpCompound, buildTbId );
1058
1059   int measureTbId = createTool( tr( "TOOL_MEASURES" ) );
1060   createTool( GEOMOp::OpPointCoordinates, measureTbId );
1061   createTool( GEOMOp::OpProperties,       measureTbId );
1062   createTool( GEOMOp::OpCenterMass,       measureTbId );
1063   createTool( GEOMOp::OpInertia,          measureTbId );
1064   createTool( GEOMOp::OpNormale,          measureTbId );
1065   createTool( separator(),                measureTbId );
1066   createTool( GEOMOp::OpBoundingBox,      measureTbId );
1067   createTool( GEOMOp::OpMinDistance,      measureTbId );
1068   createTool( GEOMOp::OpAngle,            measureTbId );
1069   createTool( GEOMOp::OpTolerance  ,      measureTbId );
1070   createTool( separator(),                measureTbId );
1071   createTool( GEOMOp::OpFreeBoundaries,   measureTbId );
1072   createTool( GEOMOp::OpFreeFaces,        measureTbId );
1073   createTool( separator(),                measureTbId );
1074   createTool( GEOMOp::OpWhatIs,           measureTbId );
1075   createTool( GEOMOp::OpCheckShape,       measureTbId );
1076   createTool( GEOMOp::OpCheckCompound,    measureTbId );
1077
1078   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
1079   createTool( GEOMOp::OpPipeTShape, advancedTbId );
1080   //@@ 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 @@//
1081
1082   // ---- create popup menus --------------------------
1083
1084   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1085   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1086
1087   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1088   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1089
1090   QString autoColorPrefix =
1091     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1092
1093   QtxPopupMgr* mgr = popupMgr();
1094   mgr->insert( action(  GEOMOp::OpRename ), -1, -1 );  // rename
1095   mgr->setRule( action( GEOMOp::OpRename ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
1096   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
1097   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1098   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
1099   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1100   mgr->insert( action(  GEOMOp::OpShowChildren ), -1, -1 ); // show children
1101   mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1102   mgr->insert( action(  GEOMOp::OpHideChildren ), -1, -1 ); // hide children
1103   mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1104   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1105   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1106   mgr->insert( separator(), -1, -1 );     // -----------
1107   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1108   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1109   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1110   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1111   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1112   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1113   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1114   mgr->insert( separator(), dispmodeId, -1 );
1115   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1116   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1117   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1118   mgr->insert( separator(), -1, -1 );     // -----------
1119   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1120   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1121   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1122   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1123   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1124   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1125   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1126   mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1127   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1128   //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule );
1129   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule );
1130   mgr->insert( separator(), -1, -1 );     // -----------
1131   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1132   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1133   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1134   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1135   mgr->insert( separator(), -1, -1 );     // -----------
1136
1137   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1138           onlyComponent = "((type='Component') and selcount=1)",
1139           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1140           types = "'Shape' 'Group'";
1141
1142   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1143   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1144
1145   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1146   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1147
1148   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1149   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1150
1151   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1152
1153   int selectonlyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1154   mgr->insert( action(GEOMOp::OpSelectVertex),   selectonlyId, -1);                                  //Vertex
1155   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1156   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1157   mgr->insert( action(GEOMOp::OpSelectEdge),     selectonlyId, -1);                                  //Edge
1158   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1159   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1160   mgr->insert( action(GEOMOp::OpSelectWire),     selectonlyId, -1);                                  //Wire
1161   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1162   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1163   mgr->insert( action(GEOMOp::OpSelectFace),     selectonlyId, -1);                                  //Face
1164   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1165   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1166   mgr->insert( action(GEOMOp::OpSelectShell),    selectonlyId, -1);                                  //Shell
1167   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1168   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1169   mgr->insert( action(GEOMOp::OpSelectSolid),    selectonlyId, -1);                                  //Solid
1170   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1171   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1172   mgr->insert( action(GEOMOp::OpSelectCompound), selectonlyId, -1);                                  //Compound
1173   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1174   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1175   mgr->insert( separator(), selectonlyId, -1);
1176   mgr->insert( action(GEOMOp::OpSelectAll),      selectonlyId, -1);                                  //Clear selection filter
1177   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1178   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1179   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1180   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1181   mgr->insert( separator(), -1, -1 );
1182
1183   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1184 }
1185
1186 //=======================================================================
1187 // function : GeometryGUI::activateModule()
1188 // purpose  : Called when GEOM module is activated
1189 //=======================================================================
1190 bool GeometryGUI::activateModule( SUIT_Study* study )
1191 {
1192   if ( CORBA::is_nil( myComponentGeom ) )
1193     return false;
1194
1195   bool res = SalomeApp_Module::activateModule( study );
1196
1197   if ( !res )
1198     return false;
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   int operationsGroup = addPreference( tr( "PREF_GROUP_OPERATIONS" ), tabId );
1641   setPreferenceProperty( operationsGroup, "columns", 2 );
1642   
1643   addPreference( tr( "GEOM_PREVIEW" ), operationsGroup,
1644                  LightApp_Preferences::Bool, "Geometry", "geom_preview" );
1645   
1646 }
1647
1648 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1649 {
1650   if (section == "Geometry") {
1651     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1652     if (param == QString("SettingsGeomStep")) {
1653       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1654       EmitSignalDefaultStepValueChanged(spin_step);
1655     }
1656   }
1657 }
1658
1659 LightApp_Displayer* GeometryGUI::displayer()
1660 {
1661   if( !myDisplayer )
1662     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1663   return myDisplayer;
1664 }
1665
1666 void GeometryGUI::setLocalSelectionMode(const int mode)
1667 {
1668   myLocalSelectionMode = mode;
1669 }
1670 int GeometryGUI::getLocalSelectionMode() const
1671 {
1672   return myLocalSelectionMode;
1673 }
1674
1675 const char gSeparator = '_'; // character used to separate parameter names
1676 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1677
1678 /*!
1679  * \brief Store visual parameters
1680  *
1681  * This method is called just before the study document is saved.
1682  * Store visual parameters in AttributeParameter attribue(s)
1683  */
1684 void GeometryGUI::storeVisualParameters (int savePoint)
1685 {
1686   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1687   if (!appStudy || !appStudy->studyDS())
1688     return;
1689   _PTR(Study) studyDS = appStudy->studyDS();
1690
1691   // componentName is used for encoding of entries when storing them in IParameters
1692   std::string componentName = myComponentGeom->ComponentDataType();
1693   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1694   //if (!aSComponent) return;
1695
1696   // IParameters
1697   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1698                                                              componentName.c_str(),
1699                                                              savePoint);
1700   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1701
1702   QList<SUIT_ViewManager*> lst;
1703   QList<SUIT_ViewManager*>::Iterator it;
1704
1705   // main cycle to store parameters of displayed objects
1706   lst.clear();
1707   getApp()->viewManagers(lst);
1708   for (it = lst.begin(); it != lst.end(); it++) {
1709     SUIT_ViewManager* vman = *it;
1710     QString vType = vman->getType();
1711     int aMgrId = vman->getGlobalId();
1712     // saving VTK actors properties
1713     QVector<SUIT_ViewWindow*> views = vman->getViews();
1714     for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
1715       const ObjMap anObjects = appStudy->getObjectMap(aMgrId);
1716       ObjMap::ConstIterator o_it = anObjects.begin();
1717       for( ;o_it != anObjects.end(); o_it++ ) {
1718         const PropMap aProps = o_it.value();
1719
1720         //Check that object exists in the study
1721         _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
1722         if ( !obj )
1723           continue;
1724         // entry is "encoded" = it does NOT contain component adress, since it is a
1725         // subject to change on next component loading
1726
1727         std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName);
1728
1729         _PTR(GenericAttribute) anAttr;
1730         if( !obj->FindAttribute(anAttr, "AttributeIOR"))
1731           continue;
1732
1733         std::string param, occParam = vType.toLatin1().data();
1734         occParam += NAME_SEPARATOR;
1735         occParam += QString::number(aMgrId).toLatin1().data();
1736         occParam += NAME_SEPARATOR;
1737
1738         param = occParam + VISIBILITY_PROP;
1739         ip->setParameter(entry, param, aProps.value(VISIBILITY_PROP).toInt() == 1 ? "On" : "Off");
1740
1741         param = occParam + DISPLAY_MODE_PROP;
1742
1743         ip->setParameter(entry, param, QString::number(aProps.value(DISPLAY_MODE_PROP).toInt()).toLatin1().data());
1744
1745         QColor c = aProps.value(COLOR_PROP).value<QColor>();
1746         QString colorStr = QString::number(c.red()/255.);
1747         colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.green()/255.);
1748         colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.blue()/255.);
1749         param = occParam + COLOR_PROP;
1750         ip->setParameter(entry, param, colorStr.toLatin1().data());
1751
1752         if(vType == SVTK_Viewer::Type()) {
1753           param = occParam + OPACITY_PROP;
1754           ip->setParameter(entry, param, QString::number(1. - aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1755         } else if (vType == SOCC_Viewer::Type()) {
1756           param = occParam + TRANSPARENCY_PROP;
1757           ip->setParameter(entry, param, QString::number(aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1758         }
1759
1760         param = occParam + ISOS_PROP;
1761         ip->setParameter(entry, param, aProps.value(ISOS_PROP).toString().toLatin1().data());
1762
1763         param = occParam + VECTOR_MODE_PROP;
1764         ip->setParameter(entry, param, QString::number(aProps.value(VECTOR_MODE_PROP).toInt()).toLatin1().data());
1765
1766         param = occParam + DEFLECTION_COEFF_PROP;
1767         ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data());
1768
1769         param = occParam + DEFLECTION_COEFF_PROP;
1770         ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data());
1771
1772         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
1773         if(aProps.contains(MARKER_TYPE_PROP)) {
1774           param = occParam + MARKER_TYPE_PROP;
1775           ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data());
1776         }
1777
1778       } // object iterator
1779     } // for (views)
1780   } // for (viewManagers)
1781 }
1782 /*!
1783  * \brief Restore visual parameters
1784  *
1785  * This method is called after the study document is opened.
1786  * Restore visual parameters from AttributeParameter attribue(s)
1787  */
1788 void GeometryGUI::restoreVisualParameters (int savePoint)
1789 {
1790   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1791   if (!appStudy || !appStudy->studyDS())
1792     return;
1793   _PTR(Study) studyDS = appStudy->studyDS();
1794
1795   // componentName is used for encoding of entries when storing them in IParameters
1796   std::string componentName = myComponentGeom->ComponentDataType();
1797   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1798   //if (!aSComponent) return;
1799
1800   // IParameters
1801   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1802                                                              componentName.c_str(),
1803                                                              savePoint);
1804   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1805
1806   std::vector<std::string> entries = ip->getEntries();
1807
1808   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1809   {
1810     // entry is a normal entry - it should be "decoded" (setting base adress of component)
1811     QString entry (ip->decodeEntry(*entIt).c_str());
1812
1813     // Check that the entry corresponds to a real object in the Study
1814     // as the object may be deleted or modified after the visual state is saved.
1815     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1816     if (!so) continue; //Skip the not existent entry
1817
1818     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1819     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1820
1821     std::vector<std::string>::iterator namesIt = paramNames.begin();
1822     std::vector<std::string>::iterator valuesIt = paramValues.begin();
1823
1824     // actors are stored in a map after displaying of them for
1825     // quicker access in the future: map < viewID to actor >
1826     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
1827     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1828
1829     QString viewerTypStr;
1830     QString viewIndexStr;
1831     int viewIndex;
1832     QVector<PropMap> aListOfMap;
1833
1834     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1835     {
1836       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1837       // '_' is used as separator and should not be used in viewer type or parameter names.
1838       QStringList lst = QString((*namesIt).c_str()).split(NAME_SEPARATOR, QString::SkipEmptyParts);
1839       if (lst.size() != 3)
1840         continue;
1841
1842       viewerTypStr = lst[0];
1843       viewIndexStr = lst[1];
1844       QString paramNameStr = lst[2];
1845
1846       bool ok;
1847       viewIndex = viewIndexStr.toUInt(&ok);
1848       if (!ok) // bad conversion of view index to integer
1849         continue;
1850
1851       if((viewIndex + 1) > aListOfMap.count()) {
1852         aListOfMap.resize(viewIndex + 1);
1853       }
1854
1855       QString val((*valuesIt).c_str());
1856       if(paramNameStr == VISIBILITY_PROP){
1857         aListOfMap[viewIndex].insert(VISIBILITY_PROP, val == "On" ? 1 : 0);
1858
1859       } else if(paramNameStr == OPACITY_PROP) {
1860         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, 1. - val.toDouble());
1861
1862       }        else if(paramNameStr == TRANSPARENCY_PROP) {
1863         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, val.toDouble());
1864
1865       } else if(paramNameStr == DISPLAY_MODE_PROP) {
1866         aListOfMap[viewIndex].insert( DISPLAY_MODE_PROP, val.toInt());
1867
1868       } else if(paramNameStr == ISOS_PROP) {
1869         aListOfMap[viewIndex].insert( ISOS_PROP, val);
1870
1871       } else if(paramNameStr == COLOR_PROP) {
1872         QStringList rgb = val.split(DIGIT_SEPARATOR);
1873         if(rgb.count() == 3) {
1874           QColor c(int(rgb[0].toDouble()*255), int(rgb[1].toDouble()*255), int(rgb[2].toDouble()*255));
1875           aListOfMap[viewIndex].insert( COLOR_PROP, c);
1876         }
1877       } else if(paramNameStr == VECTOR_MODE_PROP) {
1878         aListOfMap[viewIndex].insert( VECTOR_MODE_PROP, val.toInt());
1879
1880       }  else if(paramNameStr == DEFLECTION_COEFF_PROP) {
1881         aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble());
1882       }  else if(paramNameStr == MARKER_TYPE_PROP) {
1883         aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val);
1884       }
1885
1886     } // for names/parameters iterator
1887
1888     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
1889
1890     for (int index = 0 ; index < aListOfMap.count(); index++) {
1891
1892       appStudy->setObjectPropMap(index, entry, aListOfMap[index]);
1893
1894       QColor c = aListOfMap[index].value(COLOR_PROP).value<QColor>();
1895       //Get Visibility property of the current PropMap
1896       if (aListOfMap[index].value(VISIBILITY_PROP) == 1) {
1897         SUIT_ViewManager* vman = lst.at(index);
1898         SUIT_ViewModel* vmodel = vman->getViewModel();
1899         displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1900       }
1901     }
1902
1903   } // for entries iterator
1904
1905   // update all VTK and OCC views
1906   QList<SUIT_ViewManager*> lst;
1907   getApp()->viewManagers(lst);
1908   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
1909     SUIT_ViewModel* vmodel = (*it)->getViewModel();
1910     if (!vmodel)
1911       continue;
1912     if (vmodel->getType() == SVTK_Viewer::Type()) {
1913       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
1914       vtkView->getRenderer()->ResetCameraClippingRange();
1915       vtkView->Repaint();
1916     }
1917     else if (vmodel->getType() == SOCC_Viewer::Type()) {
1918       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
1919       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
1920       if (occVMod)
1921         occVMod->Repaint();
1922     }
1923   }
1924 }
1925
1926 void GeometryGUI::onViewAboutToShow()
1927 {
1928   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
1929   QAction* a = action( GEOMOp::OpSwitchVectors );
1930   if ( window ) {
1931     a->setEnabled(true);
1932     bool vmode = window->property("VectorsMode").toBool();
1933     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
1934   } else {
1935     a->setText ( tr("MEN_VECTOR_MODE_ON") );
1936     a->setEnabled(false);
1937   }
1938 }