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