]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI.cxx
Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
1 // Copyright (C) 2007-2011  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 //  File   : GeometryGUI.cxx
23 //  Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24
25 #include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
26 #include "Python.h"
27 #include "GeometryGUI.h"
28 #include "GeometryGUI_Operations.h"
29 #include "GEOMGUI_OCCSelector.h"
30 #include "GEOMGUI_Selection.h"
31 #include "GEOM_Displayer.h"
32 #include "GEOM_AISShape.hxx"
33
34 #include "GEOM_Actor.h"
35
36 #include <SUIT_Desktop.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ViewManager.h>
41
42 #include <OCCViewer_ViewWindow.h>
43 #include <OCCViewer_ViewPort3d.h>
44 #include <OCCViewer_ViewModel.h>
45 #include <OCCViewer_ViewManager.h>
46
47 #include <SOCC_ViewModel.h>
48 #include <SOCC_ViewWindow.h>
49
50 #include <SVTK_ViewWindow.h>
51 #include <SVTK_RenderWindowInteractor.h>
52 #include <SVTK_InteractorStyle.h>
53 #include <SVTK_ViewModel.h>
54
55 #include <SalomeApp_Application.h>
56 #include <SalomeApp_DataObject.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::OpDelete
356                              << GEOMOp::OpShow
357                              << GEOMOp::OpShowOnly
358                              << GEOMOp::OpShowChildren
359                              << GEOMOp::OpHideChildren
360                              << GEOMOp::OpUnpublishObject
361                              << GEOMOp::OpPublishObject
362                              << GEOMOp::OpPointMarker;
363   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommands.contains( id ) )
364       return;
365
366   // fix for IPAL9103, point 2
367   if ( CORBA::is_nil( GetGeomGen() ) ) {
368     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
369     return;
370   }
371
372   QString libName;
373   // find corresponding GUI library
374   switch ( id ) {
375   case GEOMOp::OpOriginAndVectors: // MENU BASIC - ORIGIN AND BASE VECTORS
376     createOriginAndBaseVectors(); // internal operation
377     return;
378   case GEOMOp::OpImport:           // MENU FILE - IMPORT
379   case GEOMOp::OpExport:           // MENU FILE - EXPORT
380   case GEOMOp::OpSelectVertex:     // POPUP MENU - SELECT ONLY - VERTEX
381   case GEOMOp::OpSelectEdge:       // POPUP MENU - SELECT ONLY - EDGE
382   case GEOMOp::OpSelectWire:       // POPUP MENU - SELECT ONLY - WIRE
383   case GEOMOp::OpSelectFace:       // POPUP MENU - SELECT ONLY - FACE
384   case GEOMOp::OpSelectShell:      // POPUP MENU - SELECT ONLY - SHELL
385   case GEOMOp::OpSelectSolid:      // POPUP MENU - SELECT ONLY - SOLID
386   case GEOMOp::OpSelectCompound:   // POPUP MENU - SELECT ONLY - COMPOUND
387   case GEOMOp::OpSelectAll:        // POPUP MENU - SELECT ONLY - SELECT ALL
388   case GEOMOp::OpDelete:           // MENU EDIT - DELETE
389   case GEOMOp::OpCheckGeom:        // MENU TOOLS - CHECK GEOMETRY
390   case GEOMOp::OpDeflection:       // POPUP MENU - DEFLECTION COEFFICIENT
391   case GEOMOp::OpColor:            // POPUP MENU - COLOR
392   case GEOMOp::OpTransparency:     // POPUP MENU - TRANSPARENCY
393   case GEOMOp::OpIncrTransparency: // SHORTCUT   - INCREASE TRANSPARENCY
394   case GEOMOp::OpDecrTransparency: // SHORTCUT   - DECREASE TRANSPARENCY
395   case GEOMOp::OpIsos:             // POPUP MENU - ISOS
396   case GEOMOp::OpIncrNbIsos:       // SHORTCUT   - INCREASE NB ISOS
397   case GEOMOp::OpDecrNbIsos:       // SHORTCUT   - DECREASE NB ISOS
398   case GEOMOp::OpAutoColor:        // POPUP MENU - AUTO COLOR
399   case GEOMOp::OpNoAutoColor:      // POPUP MENU - DISABLE AUTO COLOR
400   case GEOMOp::OpShowChildren:     // POPUP MENU - SHOW CHILDREN
401   case GEOMOp::OpHideChildren:     // POPUP MENU - HIDE CHILDREN
402   case GEOMOp::OpUnpublishObject:  // POPUP MENU - UNPUBLISH
403   case GEOMOp::OpPublishObject:    // ROOT GEOM OBJECT - POPUP MENU - PUBLISH
404   case GEOMOp::OpPointMarker:      // POPUP MENU - POINT MARKER
405     libName = "GEOMToolsGUI";
406     break;
407   case GEOMOp::OpDisplayMode:      // MENU VIEW - WIREFRAME/SHADING
408   case GEOMOp::OpShowAll:          // MENU VIEW - SHOW ALL
409   case GEOMOp::OpShowOnly:         // MENU VIEW - DISPLAY ONLY
410   case GEOMOp::OpHideAll:          // MENU VIEW - ERASE ALL
411   case GEOMOp::OpHide:             // MENU VIEW - ERASE
412   case GEOMOp::OpShow:             // MENU VIEW - DISPLAY
413   case GEOMOp::OpSwitchVectors:    // MENU VIEW - VECTOR MODE
414   case GEOMOp::OpWireframe:        // POPUP MENU - WIREFRAME
415   case GEOMOp::OpShading:          // POPUP MENU - SHADING
416   case GEOMOp::OpVectors:          // POPUP MENU - VECTORS
417     libName = "DisplayGUI";
418     break;
419   case GEOMOp::OpPoint:            // MENU BASIC - POINT
420   case GEOMOp::OpLine:             // MENU BASIC - LINE
421   case GEOMOp::OpCircle:           // MENU BASIC - CIRCLE
422   case GEOMOp::OpEllipse:          // MENU BASIC - ELLIPSE
423   case GEOMOp::OpArc:              // MENU BASIC - ARC
424   case GEOMOp::OpVector:           // MENU BASIC - VECTOR
425   case GEOMOp::OpPlane:            // MENU BASIC - PLANE
426   case GEOMOp::OpCurve:            // MENU BASIC - CURVE
427   case GEOMOp::OpLCS:              // MENU BASIC - LOCAL COORDINATE SYSTEM
428     libName = "BasicGUI";
429     break;
430   case GEOMOp::OpBox:              // MENU PRIMITIVE - BOX
431   case GEOMOp::OpCylinder:         // MENU PRIMITIVE - CYLINDER
432   case GEOMOp::OpSphere:           // MENU PRIMITIVE - SPHERE
433   case GEOMOp::OpTorus:            // MENU PRIMITIVE - TORUS
434   case GEOMOp::OpCone:             // MENU PRIMITIVE - CONE
435   case GEOMOp::OpRectangle:        // MENU PRIMITIVE - FACE
436   case GEOMOp::OpDisk:             // MENU PRIMITIVE - DISK
437     libName = "PrimitiveGUI";
438     break;
439   case GEOMOp::OpPrism:            // MENU GENERATION - PRISM
440   case GEOMOp::OpRevolution:       // MENU GENERATION - REVOLUTION
441   case GEOMOp::OpFilling:          // MENU GENERATION - FILLING
442   case GEOMOp::OpPipe:             // MENU GENERATION - PIPE
443     libName = "GenerationGUI";
444     break;
445   case GEOMOp::Op2dSketcher:       // MENU ENTITY - SKETCHER
446   case GEOMOp::Op3dSketcher:       // MENU ENTITY - 3D SKETCHER
447   case GEOMOp::OpExplode:          // MENU ENTITY - EXPLODE
448     libName = "EntityGUI";
449     break;
450   case GEOMOp::OpEdge:             // MENU BUILD - EDGE
451   case GEOMOp::OpWire:             // MENU BUILD - WIRE
452   case GEOMOp::OpFace:             // MENU BUILD - FACE
453   case GEOMOp::OpShell:            // MENU BUILD - SHELL
454   case GEOMOp::OpSolid:            // MENU BUILD - SOLID
455   case GEOMOp::OpCompound:         // MENU BUILD - COMPUND
456     libName = "BuildGUI";
457     break;
458   case GEOMOp::OpFuse:             // MENU BOOLEAN - FUSE
459   case GEOMOp::OpCommon:           // MENU BOOLEAN - COMMON
460   case GEOMOp::OpCut:              // MENU BOOLEAN - CUT
461   case GEOMOp::OpSection:          // MENU BOOLEAN - SECTION
462     libName = "BooleanGUI";
463     break;
464   case GEOMOp::OpTranslate:        // MENU TRANSFORMATION - TRANSLATION
465   case GEOMOp::OpRotate:           // MENU TRANSFORMATION - ROTATION
466   case GEOMOp::OpChangeLoc:        // MENU TRANSFORMATION - LOCATION
467   case GEOMOp::OpMirror:           // MENU TRANSFORMATION - MIRROR
468   case GEOMOp::OpScale:            // MENU TRANSFORMATION - SCALE
469   case GEOMOp::OpOffset:           // MENU TRANSFORMATION - OFFSET
470   case GEOMOp::OpProjection:       // MENU TRANSFORMATION - PROJECTION
471   case GEOMOp::OpMultiTranslate:   // MENU TRANSFORMATION - MULTI-TRANSLATION
472   case GEOMOp::OpMultiRotate:      // MENU TRANSFORMATION - MULTI-ROTATION
473   case GEOMOp::OpReimport:         // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
474     libName = "TransformationGUI";
475     break;
476   case GEOMOp::OpPartition:        // MENU OPERATION - PARTITION
477   case GEOMOp::OpArchimede:        // MENU OPERATION - ARCHIMEDE
478   case GEOMOp::OpFillet3d:         // MENU OPERATION - FILLET
479   case GEOMOp::OpChamfer:          // MENU OPERATION - CHAMFER
480   case GEOMOp::OpClipping:         // MENU OPERATION - CLIPPING RANGE
481   case GEOMOp::OpShapesOnShape:    // MENU OPERATION - GET SHAPES ON SHAPE
482   case GEOMOp::OpFillet2d:         // MENU OPERATION - FILLET 2D
483   case GEOMOp::OpFillet1d:         // MENU OPERATION - FILLET 1D
484   case GEOMOp::OpSharedShapes:     // MENU OPERATION - GET SHARED SHAPES
485     libName = "OperationGUI";
486     break;
487   case GEOMOp::OpSewing:           // MENU REPAIR - SEWING
488   case GEOMOp::OpSuppressFaces:    // MENU REPAIR - SUPPRESS FACES
489   case GEOMOp::OpSuppressHoles:    // MENU REPAIR - SUPPRESS HOLE
490   case GEOMOp::OpShapeProcess:     // MENU REPAIR - SHAPE PROCESSING
491   case GEOMOp::OpCloseContour:     // MENU REPAIR - CLOSE CONTOUR
492   case GEOMOp::OpRemoveIntWires:   // MENU REPAIR - REMOVE INTERNAL WIRES
493   case GEOMOp::OpAddPointOnEdge:   // MENU REPAIR - ADD POINT ON EDGE
494   case GEOMOp::OpFreeBoundaries:   // MENU MEASURE - FREE BOUNDARIES
495   case GEOMOp::OpFreeFaces:        // MENU MEASURE - FREE FACES
496   case GEOMOp::OpOrientation:      // MENU REPAIR - CHANGE ORIENTATION
497   case GEOMOp::OpGlueFaces:        // MENU REPAIR - GLUE FACES
498   case GEOMOp::OpGlueEdges:        // MENU REPAIR - GLUE EDGES
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::OpProjection,     "PROJECTION" );
715   createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" );
716   createGeomAction( GEOMOp::OpMultiRotate,    "MUL_ROTATION" );
717
718   createGeomAction( GEOMOp::OpPartition,      "PARTITION" );
719   createGeomAction( GEOMOp::OpArchimede,      "ARCHIMEDE" );
720   createGeomAction( GEOMOp::OpFillet3d,       "FILLET" );
721   createGeomAction( GEOMOp::OpChamfer,        "CHAMFER" );
722   //createGeomAction( GEOMOp::OpClipping,        "CLIPPING" );
723   createGeomAction( GEOMOp::OpShapesOnShape,  "GET_SHAPES_ON_SHAPE" );
724   createGeomAction( GEOMOp::OpSharedShapes,   "GET_SHARED_SHAPES" );
725   createGeomAction( GEOMOp::OpFillet1d,       "FILLET_1D" );
726   createGeomAction( GEOMOp::OpFillet2d,       "FILLET_2D" );
727
728   createGeomAction( GEOMOp::OpMultiTransform, "MUL_TRANSFORM" );
729   createGeomAction( GEOMOp::OpExplodeBlock,   "EXPLODE_BLOCKS" );
730   createGeomAction( GEOMOp::OpPropagate,      "PROPAGATE" );
731
732   createGeomAction( GEOMOp::OpSewing,           "SEWING" );
733   createGeomAction( GEOMOp::OpGlueFaces,        "GLUE_FACES" );
734   createGeomAction( GEOMOp::OpGlueEdges,        "GLUE_EDGES" );
735   createGeomAction( GEOMOp::OpLimitTolerance,   "LIMIT_TOLERANCE" );
736   createGeomAction( GEOMOp::OpSuppressFaces,    "SUPPRESS_FACES" );
737   createGeomAction( GEOMOp::OpSuppressHoles,    "SUPPERSS_HOLES" );
738   createGeomAction( GEOMOp::OpShapeProcess,     "SHAPE_PROCESS" );
739   createGeomAction( GEOMOp::OpCloseContour,     "CLOSE_CONTOUR" );
740   createGeomAction( GEOMOp::OpRemoveIntWires,   "SUPPRESS_INT_WIRES" );
741   createGeomAction( GEOMOp::OpAddPointOnEdge,   "POINT_ON_EDGE" );
742   createGeomAction( GEOMOp::OpFreeBoundaries,   "CHECK_FREE_BNDS" );
743   createGeomAction( GEOMOp::OpFreeFaces,        "CHECK_FREE_FACES" );
744   createGeomAction( GEOMOp::OpOrientation,      "CHANGE_ORIENTATION" );
745   createGeomAction( GEOMOp::OpRemoveExtraEdges, "REMOVE_EXTRA_EDGES" );
746
747   createGeomAction( GEOMOp::OpPointCoordinates, "POINT_COORDS" );
748   createGeomAction( GEOMOp::OpProperties,       "BASIC_PROPS" );
749   createGeomAction( GEOMOp::OpCenterMass,       "MASS_CENTER" );
750   createGeomAction( GEOMOp::OpInertia,          "INERTIA" );
751   createGeomAction( GEOMOp::OpNormale,          "NORMALE" );
752   createGeomAction( GEOMOp::OpBoundingBox,      "BND_BOX" );
753   createGeomAction( GEOMOp::OpMinDistance,      "MIN_DIST" );
754   createGeomAction( GEOMOp::OpAngle,            "MEASURE_ANGLE" );
755
756   createGeomAction( GEOMOp::OpTolerance,        "TOLERANCE" );
757   createGeomAction( GEOMOp::OpWhatIs,           "WHAT_IS" );
758   createGeomAction( GEOMOp::OpCheckShape,       "CHECK" );
759   createGeomAction( GEOMOp::OpCheckCompound,    "CHECK_COMPOUND" );
760
761 #ifdef _DEBUG_ // PAL16821
762   createGeomAction( GEOMOp::OpCheckGeom,        "CHECK_GEOMETRY" );
763 #endif
764
765   createGeomAction( GEOMOp::OpDisplayMode,      "SHADING" );
766   createGeomAction( GEOMOp::OpShowAll,          "DISPLAY_ALL" );
767   createGeomAction( GEOMOp::OpHideAll,          "ERASE_ALL" );
768   createGeomAction( GEOMOp::OpShow,             "DISPLAY" );
769   createGeomAction( GEOMOp::OpSwitchVectors,    "VECTOR_MODE");
770   createGeomAction( GEOMOp::OpSelectVertex,     "VERTEX_SEL_ONLY" ,"", 0, true );
771   createGeomAction( GEOMOp::OpSelectEdge,       "EDGE_SEL_ONLY", "", 0, true );
772   createGeomAction( GEOMOp::OpSelectWire,       "WIRE_SEL_ONLY", "",  0, true );
773   createGeomAction( GEOMOp::OpSelectFace,       "FACE_SEL_ONLY", "", 0, true );
774   createGeomAction( GEOMOp::OpSelectShell,      "SHELL_SEL_ONLY", "",  0, true );
775   createGeomAction( GEOMOp::OpSelectSolid,      "SOLID_SEL_ONLY", "", 0, true );
776   createGeomAction( GEOMOp::OpSelectCompound,   "COMPOUND_SEL_ONLY", "",  0, true );
777   createGeomAction( GEOMOp::OpSelectAll,        "ALL_SEL_ONLY", "",  0, true );
778   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
779   createGeomAction( GEOMOp::OpHide,             "ERASE" );
780
781   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
782   createGeomAction( GEOMOp::OpShading,          "POP_SHADING", "", 0, true );
783   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
784   createGeomAction( GEOMOp::OpDeflection,       "POP_DEFLECTION" );
785   createGeomAction( GEOMOp::OpColor,            "POP_COLOR" );
786   createGeomAction( GEOMOp::OpTransparency,     "POP_TRANSPARENCY" );
787   createGeomAction( GEOMOp::OpIsos,             "POP_ISOS" );
788   createGeomAction( GEOMOp::OpAutoColor,        "POP_AUTO_COLOR" );
789   createGeomAction( GEOMOp::OpNoAutoColor,      "POP_DISABLE_AUTO_COLOR" );
790   createGeomAction( GEOMOp::OpGroupCreatePopup, "POP_CREATE_GROUP" );
791   createGeomAction( GEOMOp::OpShowChildren,     "POP_SHOW_CHILDREN" );
792   createGeomAction( GEOMOp::OpHideChildren,     "POP_HIDE_CHILDREN" );
793   createGeomAction( GEOMOp::OpUnpublishObject,  "POP_UNPUBLISH_OBJ" );
794   createGeomAction( GEOMOp::OpPublishObject,    "POP_PUBLISH_OBJ" );
795   createGeomAction( GEOMOp::OpPointMarker,      "POP_POINT_MARKER" );
796
797   createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" );
798
799   // Create actions for increase/decrease transparency shortcuts
800   createGeomAction( GEOMOp::OpIncrTransparency, "", "", 0, false,
801                     "Geometry:Increase transparency");
802   createGeomAction( GEOMOp::OpDecrTransparency, "", "", 0, false,
803                     "Geometry:Decrease transparency");
804
805   // Create actions for increase/decrease number of isolines
806   createGeomAction( GEOMOp::OpIncrNbIsos, "", "", 0, false,
807                     "Geometry:Increase number of isolines");
808   createGeomAction( GEOMOp::OpDecrNbIsos, "", "", 0, false,
809                     "Geometry:Decrease number of isolines");
810
811 //   createGeomAction( GEOMOp::OpPipeTShapeGroups, "PIPETSHAPEGROUPS" );
812   //@@ 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 @@//
813
814   // ---- create menus --------------------------
815
816   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
817   createMenu( separator(),      fileId, 10 );
818   createMenu( GEOMOp::OpImport, fileId, 10 );
819   createMenu( GEOMOp::OpExport, fileId, 10 );
820   createMenu( separator(),      fileId, -1 );
821
822   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
823   createMenu( GEOMOp::OpDelete, editId, -1 );
824
825   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
826
827   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
828   createMenu( GEOMOp::OpPoint,   basicId, -1 );
829   createMenu( GEOMOp::OpLine,    basicId, -1 );
830   createMenu( GEOMOp::OpCircle,  basicId, -1 );
831   createMenu( GEOMOp::OpEllipse, basicId, -1 );
832   createMenu( GEOMOp::OpArc,     basicId, -1 );
833   createMenu( GEOMOp::OpCurve,   basicId, -1 );
834   createMenu( separator(),       basicId, -1 );
835   createMenu( GEOMOp::OpVector,  basicId, -1 );
836   createMenu( GEOMOp::OpPlane,   basicId, -1 );
837   createMenu( GEOMOp::OpLCS,     basicId, -1 );
838   createMenu( GEOMOp::OpOriginAndVectors, basicId, -1 );
839
840   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
841   createMenu( GEOMOp::OpBox,       primId, -1 );
842   createMenu( GEOMOp::OpCylinder,  primId, -1 );
843   createMenu( GEOMOp::OpSphere,    primId, -1 );
844   createMenu( GEOMOp::OpTorus,     primId, -1 );
845   createMenu( GEOMOp::OpCone,      primId, -1 );
846   createMenu( GEOMOp::OpRectangle, primId, -1 );
847   createMenu( GEOMOp::OpDisk,      primId, -1 );
848
849   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
850   createMenu( GEOMOp::OpPrism,      genId, -1 );
851   createMenu( GEOMOp::OpRevolution, genId, -1 );
852   createMenu( GEOMOp::OpFilling,    genId, -1 );
853   createMenu( GEOMOp::OpPipe,       genId, -1 );
854
855   int advId = createMenu( tr( "MEN_ADVANCED" ), newEntId, -1 );
856   createMenu( GEOMOp::OpPipeTShape, advId, -1 );
857 //   createMenu( GEOMOp::OpPipeTShapeGroups, advId, -1 );
858   //@@ 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 @@//
859
860   createMenu( separator(), newEntId, -1 );
861
862   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
863   createMenu( GEOMOp::OpGroupCreate, groupId, -1 );
864   createMenu( GEOMOp::OpGroupEdit,   groupId, -1 );
865
866   createMenu( separator(), newEntId, -1 );
867
868   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
869   createMenu( GEOMOp::OpQuadFace,  blocksId, -1 );
870   createMenu( GEOMOp::OpHexaSolid, blocksId, -1 );
871
872   createMenu( separator(),          newEntId, -1 );
873
874   createMenu( GEOMOp::Op2dSketcher, newEntId, -1 );
875   createMenu( GEOMOp::Op3dSketcher, newEntId, -1 );
876
877   createMenu( separator(),          newEntId, -1 );
878
879   createMenu( GEOMOp::OpExplode,    newEntId, -1 );
880
881   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
882   createMenu( GEOMOp::OpEdge,     buildId, -1 );
883   createMenu( GEOMOp::OpWire,     buildId, -1 );
884   createMenu( GEOMOp::OpFace,     buildId, -1 );
885   createMenu( GEOMOp::OpShell,    buildId, -1 );
886   createMenu( GEOMOp::OpSolid,    buildId, -1 );
887   createMenu( GEOMOp::OpCompound, buildId, -1 );
888
889   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
890
891   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
892   createMenu( GEOMOp::OpFuse,    boolId, -1 );
893   createMenu( GEOMOp::OpCommon,  boolId, -1 );
894   createMenu( GEOMOp::OpCut,     boolId, -1 );
895   createMenu( GEOMOp::OpSection, boolId, -1 );
896
897   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
898   createMenu( GEOMOp::OpTranslate,      transId, -1 );
899   createMenu( GEOMOp::OpRotate,         transId, -1 );
900   createMenu( GEOMOp::OpChangeLoc,      transId, -1 );
901   createMenu( GEOMOp::OpMirror,         transId, -1 );
902   createMenu( GEOMOp::OpScale,          transId, -1 );
903   createMenu( GEOMOp::OpOffset,         transId, -1 );
904   createMenu( GEOMOp::OpProjection,     transId, -1 );
905   createMenu( separator(),              transId, -1 );
906   createMenu( GEOMOp::OpMultiTranslate, transId, -1 );
907   createMenu( GEOMOp::OpMultiRotate,    transId, -1 );
908
909   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
910   createMenu( GEOMOp::OpMultiTransform, blockId, -1 );
911   createMenu( GEOMOp::OpExplodeBlock,   blockId, -1 );
912   createMenu( GEOMOp::OpPropagate,      blockId, -1 );
913
914   createMenu( separator(), operId, -1 );
915
916   createMenu( GEOMOp::OpPartition,     operId, -1 );
917   createMenu( GEOMOp::OpArchimede,     operId, -1 );
918   createMenu( GEOMOp::OpShapesOnShape, operId, -1 );
919   createMenu( GEOMOp::OpSharedShapes,  operId, -1 );
920
921   createMenu( separator(), operId, -1 );
922
923   createMenu( GEOMOp::OpFillet1d,      operId, -1 );
924   createMenu( GEOMOp::OpFillet2d,      operId, -1 );
925   createMenu( GEOMOp::OpFillet3d,      operId, -1 );
926   createMenu( GEOMOp::OpChamfer,       operId, -1 );
927   //createMenu( GEOMOp::OpClipping,      operId, -1 );
928
929   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
930   createMenu( GEOMOp::OpShapeProcess,    repairId, -1 );
931   createMenu( GEOMOp::OpSuppressFaces,   repairId, -1 );
932   createMenu( GEOMOp::OpCloseContour,    repairId, -1 );
933   createMenu( GEOMOp::OpRemoveIntWires,  repairId, -1 );
934   createMenu( GEOMOp::OpSuppressHoles,   repairId, -1 );
935   createMenu( GEOMOp::OpSewing,          repairId, -1 );
936   createMenu( GEOMOp::OpGlueFaces,       repairId, -1 );
937   createMenu( GEOMOp::OpGlueEdges,       repairId, -1 );
938   createMenu( GEOMOp::OpLimitTolerance,  repairId, -1 );
939   createMenu( GEOMOp::OpAddPointOnEdge,  repairId, -1 );
940   //createMenu( GEOMOp::OpFreeBoundaries,  repairId, -1 );
941   //createMenu( GEOMOp::OpFreeFaces,       repairId, -1 );
942   createMenu( GEOMOp::OpOrientation,      repairId, -1 );
943   createMenu( GEOMOp::OpRemoveExtraEdges, repairId, -1 );
944
945   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
946   createMenu( GEOMOp::OpPointCoordinates, measurId, -1 );
947   createMenu( GEOMOp::OpProperties,       measurId, -1 );
948   createMenu( separator(),                measurId, -1 );
949   createMenu( GEOMOp::OpCenterMass,       measurId, -1 );
950   createMenu( GEOMOp::OpInertia,          measurId, -1 );
951   createMenu( GEOMOp::OpNormale,          measurId, -1 );
952   createMenu( separator(),                measurId, -1 );
953   createMenu( GEOMOp::OpFreeBoundaries,   measurId, -1 );
954   createMenu( GEOMOp::OpFreeFaces,        measurId, -1 );
955   createMenu( separator(),                measurId, -1 );
956
957   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
958   createMenu( GEOMOp::OpBoundingBox, dimId, -1 );
959   createMenu( GEOMOp::OpMinDistance, dimId, -1 );
960   createMenu( GEOMOp::OpAngle,       dimId, -1 );
961
962   createMenu( separator(),             measurId, -1 );
963   createMenu( GEOMOp::OpTolerance,     measurId, -1 );
964   createMenu( separator(),             measurId, -1 );
965   createMenu( GEOMOp::OpWhatIs,        measurId, -1 );
966   createMenu( GEOMOp::OpCheckShape,    measurId, -1 );
967   createMenu( GEOMOp::OpCheckCompound, measurId, -1 );
968
969 #ifdef _DEBUG_ // PAL16821
970   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
971   createMenu( separator(),         toolsId, -1 );
972   createMenu( GEOMOp::OpCheckGeom, toolsId, -1 );
973 #endif
974
975   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
976   createMenu( separator(),       viewId, -1 );
977
978   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
979   createMenu( GEOMOp::OpDisplayMode,   dispmodeId, -1 );
980   createMenu( separator(),             dispmodeId, -1 );
981   createMenu( GEOMOp::OpSwitchVectors, dispmodeId, -1 );
982
983   createMenu( separator(),       viewId, -1 );
984   createMenu( GEOMOp::OpShowAll, viewId, -1 );
985   createMenu( GEOMOp::OpHideAll, viewId, -1 );
986   createMenu( separator(),       viewId, -1 );
987   createMenu( GEOMOp::OpPublishObject, viewId, -1 );
988   createMenu( separator(),       viewId, -1 );
989
990 /*
991   PAL9111:
992   because of these items are accessible through object browser and viewers
993   we have removed they from main menu
994
995   createMenu( GEOMOp::OpShow, viewId, -1 );
996   createMenu( GEOMOp::OpShowOnly, viewId, -1 );
997   createMenu( GEOMOp::OpHide, viewId, -1 );
998 */
999
1000   // ---- create toolbars --------------------------
1001
1002   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1003   createTool( GEOMOp::OpPoint,   basicTbId );
1004   createTool( GEOMOp::OpLine,    basicTbId );
1005   createTool( GEOMOp::OpCircle,  basicTbId );
1006   createTool( GEOMOp::OpEllipse, basicTbId );
1007   createTool( GEOMOp::OpArc,     basicTbId );
1008   createTool( GEOMOp::OpCurve,   basicTbId );
1009   createTool( GEOMOp::OpVector,  basicTbId );
1010   createTool( GEOMOp::OpPlane,   basicTbId );
1011   createTool( GEOMOp::OpLCS,     basicTbId );
1012   createTool( GEOMOp::OpOriginAndVectors, basicTbId );
1013
1014   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1015   createTool( GEOMOp::OpBox,       primTbId );
1016   createTool( GEOMOp::OpCylinder,  primTbId );
1017   createTool( GEOMOp::OpSphere,    primTbId );
1018   createTool( GEOMOp::OpTorus,     primTbId );
1019   createTool( GEOMOp::OpCone,      primTbId );
1020   createTool( GEOMOp::OpRectangle, primTbId );
1021   createTool( GEOMOp::OpDisk,      primTbId );
1022
1023   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1024   createTool( GEOMOp::OpFuse,    boolTbId );
1025   createTool( GEOMOp::OpCommon,  boolTbId );
1026   createTool( GEOMOp::OpCut,     boolTbId );
1027   createTool( GEOMOp::OpSection, boolTbId );
1028
1029   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1030   createTool( GEOMOp::OpPrism,      genTbId );
1031   createTool( GEOMOp::OpRevolution, genTbId );
1032   createTool( GEOMOp::OpFilling,    genTbId );
1033   createTool( GEOMOp::OpPipe,       genTbId );
1034
1035   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1036   createTool( GEOMOp::OpTranslate,      transTbId );
1037   createTool( GEOMOp::OpRotate,         transTbId );
1038   createTool( GEOMOp::OpChangeLoc,      transTbId );
1039   createTool( GEOMOp::OpMirror,         transTbId );
1040   createTool( GEOMOp::OpScale,          transTbId );
1041   createTool( GEOMOp::OpOffset,         transTbId );
1042   createTool( GEOMOp::OpProjection,     transTbId );
1043   createTool( separator(),              transTbId );
1044   createTool( GEOMOp::OpMultiTranslate, transTbId );
1045   createTool( GEOMOp::OpMultiRotate,    transTbId );
1046
1047   int operTbId = createTool( tr( "TOOL_OPERATIONS" ) );
1048   createTool( GEOMOp::Op2dSketcher,      operTbId );
1049   createTool( GEOMOp::Op3dSketcher,      operTbId );
1050   createTool( separator(),               operTbId );
1051   createTool( GEOMOp::OpExplode,         operTbId );
1052   createTool( separator(),               operTbId );
1053   createTool( GEOMOp::OpPartition,       operTbId );
1054   createTool( GEOMOp::OpArchimede,       operTbId );
1055   createTool( GEOMOp::OpShapesOnShape,   operTbId );
1056   createTool( GEOMOp::OpSharedShapes,    operTbId );
1057   createTool( separator(),               operTbId );
1058   createTool( GEOMOp::OpFillet1d,        operTbId );
1059   createTool( GEOMOp::OpFillet2d,        operTbId );
1060   createTool( GEOMOp::OpFillet3d,        operTbId );
1061   createTool( GEOMOp::OpChamfer,         operTbId );
1062
1063   int buildTbId = createTool( tr( "TOOL_BUILD" ) );
1064   createTool( GEOMOp::OpEdge,     buildTbId );
1065   createTool( GEOMOp::OpWire,     buildTbId );
1066   createTool( GEOMOp::OpFace,     buildTbId );
1067   createTool( GEOMOp::OpShell,    buildTbId );
1068   createTool( GEOMOp::OpSolid,    buildTbId );
1069   createTool( GEOMOp::OpCompound, buildTbId );
1070
1071   int measureTbId = createTool( tr( "TOOL_MEASURES" ) );
1072   createTool( GEOMOp::OpPointCoordinates, measureTbId );
1073   createTool( GEOMOp::OpProperties,       measureTbId );
1074   createTool( GEOMOp::OpCenterMass,       measureTbId );
1075   createTool( GEOMOp::OpInertia,          measureTbId );
1076   createTool( GEOMOp::OpNormale,          measureTbId );
1077   createTool( separator(),                measureTbId );
1078   createTool( GEOMOp::OpBoundingBox,      measureTbId );
1079   createTool( GEOMOp::OpMinDistance,      measureTbId );
1080   createTool( GEOMOp::OpAngle,            measureTbId );
1081   createTool( GEOMOp::OpTolerance  ,      measureTbId );
1082   createTool( separator(),                measureTbId );
1083   createTool( GEOMOp::OpFreeBoundaries,   measureTbId );
1084   createTool( GEOMOp::OpFreeFaces,        measureTbId );
1085   createTool( separator(),                measureTbId );
1086   createTool( GEOMOp::OpWhatIs,           measureTbId );
1087   createTool( GEOMOp::OpCheckShape,       measureTbId );
1088   createTool( GEOMOp::OpCheckCompound,    measureTbId );
1089
1090   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
1091   createTool( GEOMOp::OpPipeTShape, advancedTbId );
1092   //@@ 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 @@//
1093
1094   // ---- create popup menus --------------------------
1095
1096   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1097   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1098
1099   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1100   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1101
1102   QString autoColorPrefix =
1103     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1104
1105   QtxPopupMgr* mgr = popupMgr();
1106
1107   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
1108   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1109   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
1110   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1111   mgr->insert( action(  GEOMOp::OpShowChildren ), -1, -1 ); // show children
1112   mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1113
1114   mgr->insert( action(  GEOMOp::OpHideChildren ), -1, -1 ); // hide children
1115   mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1116   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1117   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1118   mgr->insert( separator(), -1, -1 );     // -----------
1119   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1120   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1121   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1122   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1123   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1124   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1125   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1126   mgr->insert( separator(), dispmodeId, -1 );
1127   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1128   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1129   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1130   mgr->insert( separator(), -1, -1 );     // -----------
1131   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1132   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1133   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1134   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1135   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1136   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1137   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1138   mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1139   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1140   //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule );
1141   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule );
1142   mgr->insert( separator(), -1, -1 );     // -----------
1143   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1144   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1145   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1146   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1147   mgr->insert( separator(), -1, -1 );     // -----------
1148
1149   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1150           onlyComponent = "((type='Component') and selcount=1)",
1151           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1152           types = "'Shape' 'Group'";
1153
1154   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1155   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1156
1157   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1158   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1159
1160   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1161   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1162
1163   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1164
1165   int selectonlyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1166   mgr->insert( action(GEOMOp::OpSelectVertex),   selectonlyId, -1);                                  //Vertex
1167   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1168   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1169   mgr->insert( action(GEOMOp::OpSelectEdge),     selectonlyId, -1);                                  //Edge
1170   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1171   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1172   mgr->insert( action(GEOMOp::OpSelectWire),     selectonlyId, -1);                                  //Wire
1173   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1174   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1175   mgr->insert( action(GEOMOp::OpSelectFace),     selectonlyId, -1);                                  //Face
1176   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1177   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1178   mgr->insert( action(GEOMOp::OpSelectShell),    selectonlyId, -1);                                  //Shell
1179   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1180   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1181   mgr->insert( action(GEOMOp::OpSelectSolid),    selectonlyId, -1);                                  //Solid
1182   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1183   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1184   mgr->insert( action(GEOMOp::OpSelectCompound), selectonlyId, -1);                                  //Compound
1185   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1186   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1187   mgr->insert( separator(), selectonlyId, -1);
1188   mgr->insert( action(GEOMOp::OpSelectAll),      selectonlyId, -1);                                  //Clear selection filter
1189   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1190   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1191   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1192   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1193   mgr->insert( separator(), -1, -1 );
1194
1195   mgr->insert( separator(), -1, -1 );     // -----------
1196   mgr->insert( action(  GEOMOp::OpUnpublishObject ), -1, -1 ); // Unpublish object
1197   mgr->setRule( action( GEOMOp::OpUnpublishObject ), QString("client='ObjectBrowser' and $type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1198
1199
1200   mgr->insert( action(  GEOMOp::OpPublishObject ), -1, -1 ); // Publish object
1201   mgr->setRule( action( GEOMOp::OpPublishObject ), QString("client='ObjectBrowser' and isComponent=true"), QtxPopupMgr::VisibleRule );
1202
1203
1204   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1205 }
1206
1207 //=======================================================================
1208 // function : GeometryGUI::activateModule()
1209 // purpose  : Called when GEOM module is activated
1210 //=======================================================================
1211 bool GeometryGUI::activateModule( SUIT_Study* study )
1212 {
1213   if ( CORBA::is_nil( myComponentGeom ) )
1214     return false;
1215
1216   bool res = SalomeApp_Module::activateModule( study );
1217
1218   if ( !res )
1219     return false;
1220   setMenuShown( true );
1221   setToolShown( true );
1222
1223   // import Python module that manages GEOM plugins (need to be here because SalomePyQt API uses active module)
1224   PyGILState_STATE gstate = PyGILState_Ensure();
1225   PyObject* pluginsmanager=PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
1226   if(pluginsmanager==NULL)
1227     PyErr_Print();
1228   else
1229     {
1230       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());
1231       if(result==NULL)
1232         PyErr_Print();
1233       Py_XDECREF(result);
1234     }
1235   PyGILState_Release(gstate);
1236   // end of GEOM plugins loading
1237
1238   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1239           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1240
1241   // Reset actions accelerator keys
1242   action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
1243   action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
1244   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1245
1246   GUIMap::Iterator it;
1247   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1248     it.value()->activate( application()->desktop() );
1249
1250   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1251
1252   SUIT_ViewManager* vm;
1253   ViewManagerList OCCViewManagers, VTKViewManagers;
1254
1255   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1256   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1257   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1258     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1259
1260   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1261   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1262   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1263     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1264
1265   //NPAL 19674
1266   SALOME_ListIO selected;
1267   sm->selectedObjects( selected );
1268   sm->clearSelected();
1269
1270   // disable OCC selectors
1271   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1272   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1273   while ( itOCCSel.hasNext() )
1274     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1275       sr->setEnabled(true);
1276
1277   // disable VTK selectors
1278   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1279   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1280   while ( itVTKSel.hasNext() )
1281     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1282       sr->setEnabled(true);
1283
1284   sm->setSelectedObjects( selected, true );   //NPAL 19674
1285
1286   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1287   if ( viewMenu )
1288     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1289
1290   // 0020836 (Basic vectors and origin)
1291   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1292   if( aResourceMgr->booleanValue( "Geometry", "auto_create_base_objects", false ) ) {
1293     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1294     if( appStudy ) {
1295       _PTR(Study) studyDS = appStudy->studyDS();
1296       if( studyDS ) {
1297         _PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1298         if( !aSComponent ) // create objects automatically only if there is no GEOM component
1299           createOriginAndBaseVectors();
1300       }
1301     }
1302   }
1303
1304   return true;
1305 }
1306
1307
1308 //=======================================================================
1309 // function : GeometryGUI::deactivateModule()
1310 // purpose  : Called when GEOM module is deactivated
1311 //=======================================================================
1312 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1313 {
1314   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1315   if ( viewMenu )
1316     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1317
1318   setMenuShown( false );
1319   setToolShown( false );
1320
1321   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1322              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1323
1324   EmitSignalCloseAllDialogs();
1325
1326   GUIMap::Iterator it;
1327   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1328     it.value()->deactivate();
1329
1330   // Unset actions accelerator keys
1331   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1332   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1333   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
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 || !(aProps.count() > 0))
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         if(aProps.contains(VISIBILITY_PROP)) {
1758           param = occParam + VISIBILITY_PROP;
1759           ip->setParameter(entry, param, aProps.value(VISIBILITY_PROP).toInt() == 1 ? "On" : "Off");
1760         }
1761
1762         if(aProps.contains(DISPLAY_MODE_PROP)) {
1763           param = occParam + DISPLAY_MODE_PROP;
1764           ip->setParameter(entry, param, QString::number(aProps.value(DISPLAY_MODE_PROP).toInt()).toLatin1().data());
1765         }
1766         
1767         if(aProps.contains(COLOR_PROP)) {
1768           QColor c = aProps.value(COLOR_PROP).value<QColor>();
1769           QString colorStr = QString::number(c.red()/255.);
1770           colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.green()/255.);
1771           colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.blue()/255.);
1772           param = occParam + COLOR_PROP;
1773           ip->setParameter(entry, param, colorStr.toLatin1().data());
1774         }
1775
1776         if(vType == SVTK_Viewer::Type()) {
1777           if(aProps.contains(OPACITY_PROP)) {
1778             param = occParam + OPACITY_PROP;
1779             ip->setParameter(entry, param, QString::number(1. - aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1780           }
1781         } else if (vType == SOCC_Viewer::Type()) {
1782           if(aProps.contains(TRANSPARENCY_PROP)) {
1783             param = occParam + TRANSPARENCY_PROP;
1784             ip->setParameter(entry, param, QString::number(aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1785           }
1786         }
1787
1788         if(aProps.contains(ISOS_PROP)) {
1789           param = occParam + ISOS_PROP;
1790           ip->setParameter(entry, param, aProps.value(ISOS_PROP).toString().toLatin1().data());
1791         }
1792
1793         if(aProps.contains(VECTOR_MODE_PROP)) {
1794           param = occParam + VECTOR_MODE_PROP;
1795           ip->setParameter(entry, param, QString::number(aProps.value(VECTOR_MODE_PROP).toInt()).toLatin1().data());
1796         }
1797
1798         if(aProps.contains(DEFLECTION_COEFF_PROP)) {
1799           param = occParam + DEFLECTION_COEFF_PROP;
1800           ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data());
1801         }
1802         
1803         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
1804         if(aProps.contains(MARKER_TYPE_PROP)) {
1805           param = occParam + MARKER_TYPE_PROP;
1806           ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data());
1807         }       
1808       } // object iterator
1809     } // for (views)
1810   } // for (viewManagers)
1811 }
1812
1813 /*!
1814  * \brief Restore visual parameters
1815  *
1816  * This method is called after the study document is opened.
1817  * Restore visual parameters from AttributeParameter attribue(s)
1818  */
1819 void GeometryGUI::restoreVisualParameters (int savePoint)
1820 {
1821   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1822   if (!appStudy || !appStudy->studyDS())
1823     return;
1824   _PTR(Study) studyDS = appStudy->studyDS();
1825
1826   // componentName is used for encoding of entries when storing them in IParameters
1827   std::string componentName = myComponentGeom->ComponentDataType();
1828   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1829   //if (!aSComponent) return;
1830
1831   // IParameters
1832   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1833                                                              componentName.c_str(),
1834                                                              savePoint);
1835   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1836
1837   std::vector<std::string> entries = ip->getEntries();
1838
1839   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1840   {
1841     // entry is a normal entry - it should be "decoded" (setting base adress of component)
1842     QString entry (ip->decodeEntry(*entIt).c_str());
1843
1844     // Check that the entry corresponds to a real object in the Study
1845     // as the object may be deleted or modified after the visual state is saved.
1846     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1847     if (!so) continue; //Skip the not existent entry
1848
1849     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1850     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1851
1852     std::vector<std::string>::iterator namesIt = paramNames.begin();
1853     std::vector<std::string>::iterator valuesIt = paramValues.begin();
1854
1855     // actors are stored in a map after displaying of them for
1856     // quicker access in the future: map < viewID to actor >
1857     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
1858     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1859
1860     QString viewerTypStr;
1861     QString viewIndexStr;
1862     int viewIndex;
1863     QVector<PropMap> aListOfMap;
1864
1865     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1866     {
1867       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1868       // '_' is used as separator and should not be used in viewer type or parameter names.
1869       QStringList lst = QString((*namesIt).c_str()).split(NAME_SEPARATOR, QString::SkipEmptyParts);
1870       if (lst.size() != 3)
1871         continue;
1872
1873       viewerTypStr = lst[0];
1874       viewIndexStr = lst[1];
1875       QString paramNameStr = lst[2];
1876
1877       bool ok;
1878       viewIndex = viewIndexStr.toUInt(&ok);
1879       if (!ok) // bad conversion of view index to integer
1880         continue;
1881
1882       if((viewIndex + 1) > aListOfMap.count()) {
1883         aListOfMap.resize(viewIndex + 1);
1884       }
1885
1886       QString val((*valuesIt).c_str());
1887       if(paramNameStr == VISIBILITY_PROP){
1888         aListOfMap[viewIndex].insert(VISIBILITY_PROP, val == "On" ? 1 : 0);
1889
1890       } else if(paramNameStr == OPACITY_PROP) {
1891         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, 1. - val.toDouble());
1892
1893       }        else if(paramNameStr == TRANSPARENCY_PROP) {
1894         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, val.toDouble());
1895
1896       } else if(paramNameStr == DISPLAY_MODE_PROP) {
1897         aListOfMap[viewIndex].insert( DISPLAY_MODE_PROP, val.toInt());
1898
1899       } else if(paramNameStr == ISOS_PROP) {
1900         aListOfMap[viewIndex].insert( ISOS_PROP, val);
1901
1902       } else if(paramNameStr == COLOR_PROP) {
1903         QStringList rgb = val.split(DIGIT_SEPARATOR);
1904         if(rgb.count() == 3) {
1905           QColor c(int(rgb[0].toDouble()*255), int(rgb[1].toDouble()*255), int(rgb[2].toDouble()*255));
1906           aListOfMap[viewIndex].insert( COLOR_PROP, c);
1907         }
1908       } else if(paramNameStr == VECTOR_MODE_PROP) {
1909         aListOfMap[viewIndex].insert( VECTOR_MODE_PROP, val.toInt());
1910
1911       }  else if(paramNameStr == DEFLECTION_COEFF_PROP) {
1912         aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble());
1913       }  else if(paramNameStr == MARKER_TYPE_PROP) {
1914         aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val);
1915       }
1916
1917     } // for names/parameters iterator
1918
1919     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
1920
1921     for (int index = 0 ; index < aListOfMap.count(); index++) {
1922
1923       appStudy->setObjectPropMap(index, entry, aListOfMap[index]);
1924
1925       //Get Visibility property of the current PropMap
1926       if (aListOfMap[index].value(VISIBILITY_PROP) == 1) {
1927         SUIT_ViewManager* vman = lst.at(index);
1928         SUIT_ViewModel* vmodel = vman->getViewModel();
1929         displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1930       }
1931     }
1932
1933   } // for entries iterator
1934
1935   // update all VTK and OCC views
1936   QList<SUIT_ViewManager*> lst;
1937   getApp()->viewManagers(lst);
1938   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
1939     SUIT_ViewModel* vmodel = (*it)->getViewModel();
1940     if (!vmodel)
1941       continue;
1942     if (vmodel->getType() == SVTK_Viewer::Type()) {
1943       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
1944       vtkView->getRenderer()->ResetCameraClippingRange();
1945       vtkView->Repaint();
1946     }
1947     else if (vmodel->getType() == SOCC_Viewer::Type()) {
1948       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
1949       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
1950       if (occVMod)
1951         occVMod->Repaint();
1952     }
1953   }
1954 }
1955
1956 void GeometryGUI::onViewAboutToShow()
1957 {
1958   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
1959   QAction* a = action( GEOMOp::OpSwitchVectors );
1960   if ( window ) {
1961     a->setEnabled(true);
1962     bool vmode = window->property("VectorsMode").toBool();
1963     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
1964   } else {
1965     a->setText ( tr("MEN_VECTOR_MODE_ON") );
1966     a->setEnabled(false);
1967   }
1968 }
1969
1970 /*!
1971   Rename object by entry.
1972   \param entry entry of the object
1973   \param name new name of the object
1974   \brief Return \c true if rename operation finished successfully, \c false otherwise.
1975 */
1976 bool GeometryGUI::renameObject( const QString& entry, const QString& name) {
1977   
1978   bool appRes = SalomeApp_Module::renameObject(entry,name);
1979   if( !appRes )
1980     return false;
1981   
1982   bool result = false;
1983   
1984   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
1985   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0; 
1986
1987   if(!appStudy)
1988     return result;
1989
1990   _PTR(Study) aStudy = appStudy->studyDS();
1991
1992   if(!aStudy)
1993     return result;
1994
1995   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
1996   _PTR(GenericAttribute) anAttr;
1997   if ( obj ) {
1998     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
1999       _PTR(AttributeName) aName (anAttr);
2000       
2001       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
2002       if (!CORBA::is_nil(anObj)) {
2003         aName->SetValue( name.toLatin1().data() ); // rename the SObject
2004         anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
2005         result = true;
2006       }
2007     }
2008   }
2009   return result;
2010 }