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