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