Salome HOME
2d352d9193a94a9a449c6d500bfd97a548a1bcba
[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 #endif
467   case GEOMOp::OpPictureImport:    // MENU ENTITY - IMPORT PICTURE IN VIEWER
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 #endif
730   createGeomAction( GEOMOp::OpPictureImport,"PICTURE_IMPORT" );
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   createMenu( GEOMOp::OpPictureImport, newEntId, -1 );
930 #ifdef WITH_OPENCV
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 #endif
1101   createTool( GEOMOp::OpPictureImport,   operTbId );
1102   createTool( separator(),               operTbId );
1103
1104   createTool( GEOMOp::OpPartition,       operTbId );
1105   createTool( GEOMOp::OpArchimede,       operTbId );
1106   createTool( GEOMOp::OpShapesOnShape,   operTbId );
1107   createTool( GEOMOp::OpSharedShapes,    operTbId );
1108   createTool( separator(),               operTbId );
1109   createTool( GEOMOp::OpFillet1d,        operTbId );
1110   createTool( GEOMOp::OpFillet2d,        operTbId );
1111   createTool( GEOMOp::OpFillet3d,        operTbId );
1112   createTool( GEOMOp::OpChamfer,         operTbId );
1113
1114   int buildTbId = createTool( tr( "TOOL_BUILD" ) );
1115   createTool( GEOMOp::OpEdge,     buildTbId );
1116   createTool( GEOMOp::OpWire,     buildTbId );
1117   createTool( GEOMOp::OpFace,     buildTbId );
1118   createTool( GEOMOp::OpShell,    buildTbId );
1119   createTool( GEOMOp::OpSolid,    buildTbId );
1120   createTool( GEOMOp::OpCompound, buildTbId );
1121
1122   int measureTbId = createTool( tr( "TOOL_MEASURES" ) );
1123   createTool( GEOMOp::OpPointCoordinates, measureTbId );
1124   createTool( GEOMOp::OpProperties,       measureTbId );
1125   createTool( GEOMOp::OpCenterMass,       measureTbId );
1126   createTool( GEOMOp::OpInertia,          measureTbId );
1127   createTool( GEOMOp::OpNormale,          measureTbId );
1128   createTool( separator(),                measureTbId );
1129   createTool( GEOMOp::OpBoundingBox,      measureTbId );
1130   createTool( GEOMOp::OpMinDistance,      measureTbId );
1131   createTool( GEOMOp::OpAngle,            measureTbId );
1132   createTool( GEOMOp::OpTolerance  ,      measureTbId );
1133   createTool( separator(),                measureTbId );
1134   createTool( GEOMOp::OpFreeBoundaries,   measureTbId );
1135   createTool( GEOMOp::OpFreeFaces,        measureTbId );
1136   createTool( separator(),                measureTbId );
1137   createTool( GEOMOp::OpWhatIs,           measureTbId );
1138   createTool( GEOMOp::OpCheckShape,       measureTbId );
1139   createTool( GEOMOp::OpCheckCompound,    measureTbId );
1140
1141   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
1142   createTool( GEOMOp::OpPipeTShape, advancedTbId );
1143   //@@ 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 @@//
1144
1145   // ---- create popup menus --------------------------
1146
1147   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1148   QString clientOCC = "(client='OCCViewer')";
1149   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1150   QString clientOCC_AndSomeVisible = clientOCC + " and selcount>0 and isVisible";
1151
1152   QString clientOCCorOB = "(client='ObjectBrowser' or client='OCCViewer')";
1153   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1154   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1155   QString clientOCCorOB_AndSomeVisible = clientOCCorOB + " and selcount>0 and isVisible";
1156
1157   QString autoColorPrefix =
1158     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1159
1160   QtxPopupMgr* mgr = popupMgr();
1161
1162   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
1163   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1164   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
1165   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1166   mgr->insert( action(  GEOMOp::OpShowChildren ), -1, -1 ); // show children
1167   mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1168
1169   mgr->insert( action(  GEOMOp::OpHideChildren ), -1, -1 ); // hide children
1170   mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1171   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1172   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1173   mgr->insert( separator(), -1, -1 );     // -----------
1174   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1175   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1176   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1177   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1178   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1179   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1180   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1181   mgr->insert( action(  GEOMOp::OpTexture ), dispmodeId, -1 ); // wireframe
1182   mgr->setRule( action( GEOMOp::OpTexture ), clientOCC_AndSomeVisible, QtxPopupMgr::VisibleRule );
1183   mgr->setRule( action( GEOMOp::OpTexture), clientOCC + " and displaymode='Texture'", QtxPopupMgr::ToggleRule );
1184   mgr->insert( separator(), dispmodeId, -1 );
1185   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1186   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1187   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1188   mgr->insert( separator(), -1, -1 );     // -----------
1189   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1190   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1191   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1192   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1193   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1194   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1195   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1196   mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1197   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1198   //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule );
1199   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule );
1200   mgr->insert( action(  GEOMOp::OpSetTexture ), -1, -1 ); // texture
1201   mgr->setRule( action( GEOMOp::OpSetTexture ), clientOCCorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1202   mgr->insert( separator(), -1, -1 );     // -----------
1203   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1204   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1205   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1206   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1207   mgr->insert( separator(), -1, -1 );     // -----------
1208
1209   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1210           onlyComponent = "((type='Component') and selcount=1)",
1211           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1212           types = "'Shape' 'Group'";
1213
1214   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1215   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1216
1217   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1218   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1219
1220   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1221   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1222
1223   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1224
1225   int selectonlyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1226   mgr->insert( action(GEOMOp::OpSelectVertex),   selectonlyId, -1);                                  //Vertex
1227   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1228   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1229   mgr->insert( action(GEOMOp::OpSelectEdge),     selectonlyId, -1);                                  //Edge
1230   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1231   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1232   mgr->insert( action(GEOMOp::OpSelectWire),     selectonlyId, -1);                                  //Wire
1233   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1234   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1235   mgr->insert( action(GEOMOp::OpSelectFace),     selectonlyId, -1);                                  //Face
1236   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1237   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1238   mgr->insert( action(GEOMOp::OpSelectShell),    selectonlyId, -1);                                  //Shell
1239   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1240   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1241   mgr->insert( action(GEOMOp::OpSelectSolid),    selectonlyId, -1);                                  //Solid
1242   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1243   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1244   mgr->insert( action(GEOMOp::OpSelectCompound), selectonlyId, -1);                                  //Compound
1245   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1246   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1247   mgr->insert( separator(), selectonlyId, -1);
1248   mgr->insert( action(GEOMOp::OpSelectAll),      selectonlyId, -1);                                  //Clear selection filter
1249   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1250   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1251   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1252   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1253   mgr->insert( separator(), -1, -1 );
1254
1255   mgr->insert( separator(), -1, -1 );     // -----------
1256   mgr->insert( action(  GEOMOp::OpUnpublishObject ), -1, -1 ); // Unpublish object
1257   mgr->setRule( action( GEOMOp::OpUnpublishObject ), QString("client='ObjectBrowser' and $type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1258
1259
1260   mgr->insert( action(  GEOMOp::OpPublishObject ), -1, -1 ); // Publish object
1261   mgr->setRule( action( GEOMOp::OpPublishObject ), QString("client='ObjectBrowser' and isComponent=true"), QtxPopupMgr::VisibleRule );
1262
1263   mgr->insert( action(  GEOMOp::OpReimport ), -1, -1 );  // delete
1264   mgr->setRule( action( GEOMOp::OpReimport ), QString("$imported in {'true'} and selcount>0"), QtxPopupMgr::VisibleRule );
1265
1266   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1267 }
1268
1269 //=======================================================================
1270 // function : GeometryGUI::activateModule()
1271 // purpose  : Called when GEOM module is activated
1272 //=======================================================================
1273 bool GeometryGUI::activateModule( SUIT_Study* study )
1274 {
1275   if ( CORBA::is_nil( myComponentGeom ) )
1276     return false;
1277
1278   bool res = SalomeApp_Module::activateModule( study );
1279
1280   if ( !res )
1281     return false;
1282   setMenuShown( true );
1283   setToolShown( true );
1284
1285   // import Python module that manages GEOM plugins (need to be here because SalomePyQt API uses active module)
1286   PyGILState_STATE gstate = PyGILState_Ensure();
1287   PyObject* pluginsmanager=PyImport_ImportModuleNoBlock((char*)"salome_pluginsmanager");
1288   if(pluginsmanager==NULL)
1289     PyErr_Print();
1290   else
1291     {
1292       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());
1293       if(result==NULL)
1294         PyErr_Print();
1295       Py_XDECREF(result);
1296     }
1297   PyGILState_Release(gstate);
1298   // end of GEOM plugins loading
1299
1300   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1301           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1302
1303   // Reset actions accelerator keys
1304   action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
1305   action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
1306   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1307
1308   GUIMap::Iterator it;
1309   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1310     it.value()->activate( application()->desktop() );
1311
1312   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1313
1314   SUIT_ViewManager* vm;
1315   ViewManagerList OCCViewManagers, VTKViewManagers;
1316
1317   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1318   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1319   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1320     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1321
1322   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1323   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1324   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1325     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1326
1327   //NPAL 19674
1328   SALOME_ListIO selected;
1329   sm->selectedObjects( selected );
1330   sm->clearSelected();
1331
1332   // disable OCC selectors
1333   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1334   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1335   while ( itOCCSel.hasNext() )
1336     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1337       sr->setEnabled(true);
1338
1339   // disable VTK selectors
1340   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1341   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1342   while ( itVTKSel.hasNext() )
1343     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1344       sr->setEnabled(true);
1345
1346   sm->setSelectedObjects( selected, true );   //NPAL 19674
1347
1348   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1349   if ( viewMenu )
1350     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1351
1352   // 0020836 (Basic vectors and origin)
1353   SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1354   if( aResourceMgr->booleanValue( "Geometry", "auto_create_base_objects", false ) ) {
1355     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1356     if( appStudy ) {
1357       _PTR(Study) studyDS = appStudy->studyDS();
1358       if( studyDS ) {
1359         _PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1360         if( !aSComponent ) // create objects automatically only if there is no GEOM component
1361           createOriginAndBaseVectors();
1362       }
1363     }
1364   }
1365
1366   return true;
1367 }
1368
1369
1370 //=======================================================================
1371 // function : GeometryGUI::deactivateModule()
1372 // purpose  : Called when GEOM module is deactivated
1373 //=======================================================================
1374 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1375 {
1376   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1377   if ( viewMenu )
1378     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1379
1380   setMenuShown( false );
1381   setToolShown( false );
1382
1383   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1384              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1385
1386   EmitSignalCloseAllDialogs();
1387
1388   GUIMap::Iterator it;
1389   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1390     it.value()->deactivate();
1391
1392   // Unset actions accelerator keys
1393   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1394   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1395   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1396
1397   qDeleteAll(myOCCSelectors);
1398   myOCCSelectors.clear();
1399   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1400
1401   qDeleteAll(myVTKSelectors);
1402   myVTKSelectors.clear();
1403   getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1404
1405   return SalomeApp_Module::deactivateModule( study );
1406 }
1407
1408 //=======================================================================
1409 // function : onWindowActivated()
1410 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1411 //=======================================================================
1412 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1413 {
1414   if ( !win )
1415     return;
1416
1417   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1418   //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1419
1420   // disable non-OCC viewframe menu commands
1421 //  action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
1422   action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
1423   action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
1424   action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
1425   action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
1426   action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
1427 //  action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
1428
1429   action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
1430   action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
1431
1432   action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1433 }
1434
1435 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1436 {
1437   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1438   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1439 }
1440
1441 void GeometryGUI::viewManagers( QStringList& lst ) const
1442 {
1443   lst.append( OCCViewer_Viewer::Type() );
1444 }
1445
1446 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1447 {
1448   if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
1449   {
1450     qDebug( "connect" );
1451     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1452              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1453     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1454              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1455     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1456              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1457     connect( vm, SIGNAL( mouseRelease ( SUIT_ViewWindow*, QMouseEvent* ) ),
1458              this, SLOT( OnMouseRelease( SUIT_ViewWindow*, QMouseEvent* ) ) );
1459     
1460     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1461     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1462
1463     // disable OCC selectors
1464     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1465     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1466     while ( itOCCSel.hasNext() )
1467       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1468         sr->setEnabled(true);
1469   }
1470   else if ( vm->getType() == SVTK_Viewer::Type() )
1471   {
1472     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1473     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1474
1475     // disable VTK selectors
1476     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1477     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1478     while ( itVTKSel.hasNext() )
1479       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1480         sr->setEnabled(true);
1481   }
1482 }
1483
1484 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1485 {
1486   SUIT_ViewModel* viewer = vm->getViewModel();
1487   if ( vm->getType() == OCCViewer_Viewer::Type() )
1488   {
1489     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1490     while ( itOCCSel.hasNext() )
1491       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1492         if ( sr->viewer() == viewer )
1493         {
1494           delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1495           break;
1496         }
1497   }
1498   if ( vm->getType() == SVTK_Viewer::Type() )
1499   {
1500     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1501     while ( itVTKSel.hasNext() )
1502       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1503         if ( sr->viewer() == viewer )
1504         {
1505           delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1506           break;
1507         }
1508   }
1509 }
1510
1511 QString GeometryGUI::engineIOR() const
1512 {
1513   if ( !CORBA::is_nil( GetGeomGen() ) )
1514     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1515   return "";
1516 }
1517
1518 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1519 Handle(TColStd_HArray1OfByte) GeometryGUI::getTexture
1520 #else
1521 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture
1522 #endif
1523       (SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight)
1524 {
1525   theWidth = theHeight = 0;
1526
1527 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1528   Handle(TColStd_HArray1OfByte) aTexture;
1529 #else
1530   Handle(Graphic3d_HArray1OfBytes) aTexture;
1531 #endif
1532
1533   if (theStudy) {
1534     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1535     aTexture = aTextureMap[ theId ];
1536     if ( aTexture.IsNull() ) {
1537       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1538       if ( !aInsOp->_is_nil() ) {
1539         CORBA::Long aWidth, aHeight;
1540         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1541         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1542           theWidth  = aWidth;
1543           theHeight = aHeight;
1544
1545 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
1546           aTexture  = new TColStd_HArray1OfByte (1, aStream->length());
1547 #else
1548           aTexture  = new Graphic3d_HArray1OfBytes (1, aStream->length());
1549 #endif
1550
1551           for (int i = 0; i < aStream->length(); i++)
1552             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1553           aTextureMap[ theId ] = aTexture;
1554         }
1555       }
1556     }
1557   }
1558   return aTexture;
1559 }
1560
1561 LightApp_Selection* GeometryGUI::createSelection() const
1562 {
1563   return new GEOMGUI_Selection();
1564 }
1565
1566 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1567 {
1568   SalomeApp_Module::contextMenuPopup( client, menu, title );
1569
1570   /*
1571   SALOME_ListIO lst;
1572   getApp()->selectionMgr()->selectedObjects(lst);
1573   if (lst.Extent() < 1)
1574     return;
1575
1576   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1577   _PTR(Study) study = appStudy->studyDS();
1578
1579   bool isImported = true;
1580   SALOME_ListIteratorOfListIO anIt (lst);
1581   for (; anIt.More() && isImported; anIt.Next()) {
1582     Handle(SALOME_InteractiveObject) io = anIt.Value();
1583     _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1584     if (aSObj) {
1585       if (lst.Extent() == 1) {
1586         // Set context menu title
1587         if (client == "OCCViewer" || client == "VTKViewer")
1588           title = QString(aSObj->GetName().c_str());
1589       }
1590
1591       CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1592       GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1593       if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1594         isImported = false;
1595     } else {
1596       isImported = false;
1597     }
1598   }
1599
1600   if (isImported) {
1601     menu->addAction(action(GEOMOp::OpReimport)); // Reload imported shape
1602   }
1603   */
1604 }
1605
1606 void GeometryGUI::createPreferences()
1607 {
1608   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1609
1610   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1611   setPreferenceProperty( genGroup, "columns", 2 );
1612
1613   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1614                                 LightApp_Preferences::Selector,
1615                                 "Geometry", "display_mode" );
1616
1617   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1618                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1619
1620   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1621                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1622
1623   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1624                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1625
1626   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1627                  LightApp_Preferences::Color, "Geometry", "line_color" );
1628
1629   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1630                  LightApp_Preferences::Color, "Geometry", "point_color" );
1631
1632   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1633                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1634
1635   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1636                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1637
1638   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
1639                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
1640
1641   // Quantities with individual precision settings
1642   int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId );
1643   setPreferenceProperty( precGroup, "columns", 2 );
1644
1645   const int nbQuantities = 8;
1646   int prec[nbQuantities], ii = 0;
1647   prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup,
1648                               LightApp_Preferences::IntSpin, "Geometry", "length_precision" );
1649   prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup,
1650                               LightApp_Preferences::IntSpin, "Geometry", "angle_precision" );
1651   prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup,
1652                               LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" );
1653   prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup,
1654                               LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" );
1655   prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup,
1656                               LightApp_Preferences::IntSpin, "Geometry", "weight_precision" );
1657   prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup,
1658                               LightApp_Preferences::IntSpin, "Geometry", "density_precision" );
1659   prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup,
1660                               LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" );
1661   prec[ii  ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup,
1662                               LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" );
1663
1664   // Set property for precision value for spinboxes
1665   for ( ii = 0; ii < nbQuantities; ii++ ){
1666     setPreferenceProperty( prec[ii], "min", -14 );
1667     setPreferenceProperty( prec[ii], "max", 14 );
1668     setPreferenceProperty( prec[ii], "precision", 2 );
1669   }
1670
1671   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1672   setPreferenceProperty( VertexGroup, "columns", 2 );
1673
1674   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1675                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1676
1677   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1678                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
1679
1680   // Set property for default display mode
1681   QStringList aModesList;
1682   aModesList.append( tr("MEN_WIREFRAME") );
1683   aModesList.append( tr("MEN_SHADING") );
1684
1685   QList<QVariant> anIndexesList;
1686   anIndexesList.append(0);
1687   anIndexesList.append(1);
1688
1689   setPreferenceProperty( dispmode, "strings", aModesList );
1690   setPreferenceProperty( dispmode, "indexes", anIndexesList );
1691
1692   // Set property for step value for spinboxes
1693   setPreferenceProperty( step, "min", 1 );
1694   setPreferenceProperty( step, "max", 10000 );
1695   setPreferenceProperty( step, "precision", 3 );
1696
1697   // Set property for deflection value for spinboxes
1698   setPreferenceProperty( defl, "min", DEFLECTION_MIN );
1699   setPreferenceProperty( defl, "max", 1.0 );
1700   setPreferenceProperty( defl, "step", 1.0e-04 );
1701   setPreferenceProperty( defl, "precision", 6 );
1702
1703   // Set property vertex marker type
1704   QList<QVariant> aMarkerTypeIndicesList;
1705   QList<QVariant> aMarkerTypeIconsList;
1706
1707   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1708   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
1709     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
1710     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
1711     aMarkerTypeIndicesList << (i-1);
1712     aMarkerTypeIconsList << pixmap;
1713   }
1714
1715   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
1716   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
1717
1718   // Set property for vertex marker scale
1719   QList<QVariant> aMarkerScaleIndicesList;
1720   QStringList     aMarkerScaleValuesList;
1721
1722   for ( int iii = GEOM::MS_10; iii <= GEOM::MS_70; iii++ ) {
1723     aMarkerScaleIndicesList << iii;
1724     aMarkerScaleValuesList  << QString::number( (iii-(int)GEOM::MS_10)*0.5 + 1.0 );
1725   }
1726
1727   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
1728   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
1729
1730   int originGroup = addPreference( tr( "PREF_GROUP_ORIGIN_AND_BASE_VECTORS" ), tabId );
1731   setPreferenceProperty( originGroup, "columns", 2 );
1732
1733   int baseVectorsLength = addPreference( tr( "PREF_BASE_VECTORS_LENGTH" ), originGroup,
1734                                          LightApp_Preferences::DblSpin, "Geometry", "base_vectors_length" );
1735   setPreferenceProperty( baseVectorsLength, "min", 0.01 );
1736   setPreferenceProperty( baseVectorsLength, "max", 1000 );
1737
1738   addPreference( tr( "PREF_AUTO_CREATE" ), originGroup,
1739                  LightApp_Preferences::Bool, "Geometry", "auto_create_base_objects" );
1740
1741
1742   int operationsGroup = addPreference( tr( "PREF_GROUP_OPERATIONS" ), tabId );
1743   setPreferenceProperty( operationsGroup, "columns", 2 );
1744
1745   addPreference( tr( "GEOM_PREVIEW" ), operationsGroup,
1746                  LightApp_Preferences::Bool, "Geometry", "geom_preview" );
1747 }
1748
1749 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1750 {
1751   if (section == "Geometry") {
1752     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1753     if (param == QString("SettingsGeomStep")) {
1754       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1755       EmitSignalDefaultStepValueChanged(spin_step);
1756     }
1757   }
1758 }
1759
1760 LightApp_Displayer* GeometryGUI::displayer()
1761 {
1762   if( !myDisplayer )
1763     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1764   return myDisplayer;
1765 }
1766
1767 void GeometryGUI::setLocalSelectionMode(const int mode)
1768 {
1769   myLocalSelectionMode = mode;
1770 }
1771 int GeometryGUI::getLocalSelectionMode() const
1772 {
1773   return myLocalSelectionMode;
1774 }
1775
1776 const char gSeparator = '_'; // character used to separate parameter names
1777 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1778
1779 /*!
1780  * \brief Store visual parameters
1781  *
1782  * This method is called just before the study document is saved.
1783  * Store visual parameters in AttributeParameter attribue(s)
1784  */
1785 void GeometryGUI::storeVisualParameters (int savePoint)
1786 {
1787   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1788   if ( !appStudy || !appStudy->studyDS() )
1789     return;
1790   _PTR(Study) studyDS = appStudy->studyDS();
1791
1792   // componentName is used for encoding of entries when storing them in IParameters
1793   std::string componentName = myComponentGeom->ComponentDataType();
1794   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1795   //if (!aSComponent) return;
1796
1797   // IParameters
1798   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1799                                                              componentName.c_str(),
1800                                                              savePoint);
1801   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1802
1803   QList<SUIT_ViewManager*> lst;
1804   QList<SUIT_ViewManager*>::Iterator it;
1805
1806   // main cycle to store parameters of displayed objects
1807   lst.clear();
1808   getApp()->viewManagers(lst);
1809   for (it = lst.begin(); it != lst.end(); it++) {
1810     SUIT_ViewManager* vman = *it;
1811     QString vType = vman->getType();
1812     int aMgrId = vman->getGlobalId();
1813     // saving VTK actors properties
1814     QVector<SUIT_ViewWindow*> views = vman->getViews();
1815     for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++) {
1816       const ObjMap anObjects = appStudy->getObjectMap(aMgrId);
1817       ObjMap::ConstIterator o_it = anObjects.begin();
1818       for (; o_it != anObjects.end(); o_it++) {
1819         const PropMap aProps = o_it.value();
1820
1821         //Check that object exists in the study
1822         _PTR(SObject) obj( studyDS->FindObjectID( o_it.key().toLatin1().data() ) );
1823         if ( !obj || !(aProps.count() > 0))
1824           continue;
1825         // entry is "encoded" = it does NOT contain component adress, since it is a
1826         // subject to change on next component loading
1827
1828         std::string entry = ip->encodeEntry(o_it.key().toLatin1().data(), componentName);
1829
1830         _PTR(GenericAttribute) anAttr;
1831         if( !obj->FindAttribute(anAttr, "AttributeIOR"))
1832           continue;
1833
1834         std::string param,occParam = vType.toLatin1().data();
1835         occParam += NAME_SEPARATOR;
1836         occParam += QString::number(aMgrId).toLatin1().data();
1837         occParam += NAME_SEPARATOR;
1838
1839         if(aProps.contains(VISIBILITY_PROP)) {
1840           param = occParam + VISIBILITY_PROP;
1841           ip->setParameter(entry, param, aProps.value(VISIBILITY_PROP).toInt() == 1 ? "On" : "Off");
1842         }
1843
1844         if(aProps.contains(DISPLAY_MODE_PROP)) {
1845           param = occParam + DISPLAY_MODE_PROP;
1846           ip->setParameter(entry, param, QString::number(aProps.value(DISPLAY_MODE_PROP).toInt()).toLatin1().data());
1847         }
1848
1849         if(aProps.contains(COLOR_PROP)) {
1850           QColor c = aProps.value(COLOR_PROP).value<QColor>();
1851           QString colorStr = QString::number(c.red()/255.);
1852           colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.green()/255.);
1853           colorStr += DIGIT_SEPARATOR; colorStr += QString::number(c.blue()/255.);
1854           param = occParam + COLOR_PROP;
1855           ip->setParameter(entry, param, colorStr.toLatin1().data());
1856         }
1857
1858         if(vType == SVTK_Viewer::Type()) {
1859           if(aProps.contains(OPACITY_PROP)) {
1860             param = occParam + OPACITY_PROP;
1861             ip->setParameter(entry, param, QString::number(1. - aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1862           }
1863         } else if (vType == SOCC_Viewer::Type()) {
1864           if(aProps.contains(TRANSPARENCY_PROP)) {
1865             param = occParam + TRANSPARENCY_PROP;
1866             ip->setParameter(entry, param, QString::number(aProps.value(TRANSPARENCY_PROP).toDouble()).toLatin1().data());
1867           }
1868         }
1869
1870         if(aProps.contains(ISOS_PROP)) {
1871           param = occParam + ISOS_PROP;
1872           ip->setParameter(entry, param, aProps.value(ISOS_PROP).toString().toLatin1().data());
1873         }
1874
1875         if(aProps.contains(VECTOR_MODE_PROP)) {
1876           param = occParam + VECTOR_MODE_PROP;
1877           ip->setParameter(entry, param, QString::number(aProps.value(VECTOR_MODE_PROP).toInt()).toLatin1().data());
1878         }
1879
1880         if(aProps.contains(DEFLECTION_COEFF_PROP)) {
1881           param = occParam + DEFLECTION_COEFF_PROP;
1882           ip->setParameter(entry, param, QString::number(aProps.value(DEFLECTION_COEFF_PROP).toDouble()).toLatin1().data());
1883         }
1884
1885         //Marker type of the vertex - ONLY for the "Vertex" and "Compound of the Vertex"
1886         if(aProps.contains(MARKER_TYPE_PROP)) {
1887           param = occParam + MARKER_TYPE_PROP;
1888           ip->setParameter(entry, param, aProps.value(MARKER_TYPE_PROP).toString().toLatin1().data());
1889         }
1890       } // object iterator
1891     } // for (views)
1892   } // for (viewManagers)
1893 }
1894
1895 /*!
1896  * \brief Restore visual parameters
1897  *
1898  * This method is called after the study document is opened.
1899  * Restore visual parameters from AttributeParameter attribue(s)
1900  */
1901 void GeometryGUI::restoreVisualParameters (int savePoint)
1902 {
1903   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1904   if (!appStudy || !appStudy->studyDS())
1905     return;
1906   _PTR(Study) studyDS = appStudy->studyDS();
1907
1908   // componentName is used for encoding of entries when storing them in IParameters
1909   std::string componentName = myComponentGeom->ComponentDataType();
1910   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1911   //if (!aSComponent) return;
1912
1913   // IParameters
1914   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1915                                                              componentName.c_str(),
1916                                                              savePoint);
1917   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1918
1919   std::vector<std::string> entries = ip->getEntries();
1920
1921   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1922   {
1923     // entry is a normal entry - it should be "decoded" (setting base adress of component)
1924     QString entry (ip->decodeEntry(*entIt).c_str());
1925
1926     // Check that the entry corresponds to a real object in the Study
1927     // as the object may be deleted or modified after the visual state is saved.
1928     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1929     if (!so) continue; //Skip the not existent entry
1930
1931     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1932     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1933
1934     std::vector<std::string>::iterator namesIt = paramNames.begin();
1935     std::vector<std::string>::iterator valuesIt = paramValues.begin();
1936
1937     // actors are stored in a map after displaying of them for
1938     // quicker access in the future: map < viewID to actor >
1939     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
1940     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1941
1942     QString viewerTypStr;
1943     QString viewIndexStr;
1944     int viewIndex;
1945     QVector<PropMap> aListOfMap;
1946
1947     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1948     {
1949       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1950       // '_' is used as separator and should not be used in viewer type or parameter names.
1951       QStringList lst = QString((*namesIt).c_str()).split(NAME_SEPARATOR, QString::SkipEmptyParts);
1952       if (lst.size() != 3)
1953         continue;
1954
1955       viewerTypStr = lst[0];
1956       viewIndexStr = lst[1];
1957       QString paramNameStr = lst[2];
1958
1959       bool ok;
1960       viewIndex = viewIndexStr.toUInt(&ok);
1961       if (!ok) // bad conversion of view index to integer
1962         continue;
1963
1964       if((viewIndex + 1) > aListOfMap.count()) {
1965         aListOfMap.resize(viewIndex + 1);
1966       }
1967
1968       QString val((*valuesIt).c_str());
1969       if(paramNameStr == VISIBILITY_PROP){
1970         aListOfMap[viewIndex].insert(VISIBILITY_PROP, val == "On" ? 1 : 0);
1971
1972       } else if(paramNameStr == OPACITY_PROP) {
1973         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, 1. - val.toDouble());
1974
1975       }        else if(paramNameStr == TRANSPARENCY_PROP) {
1976         aListOfMap[viewIndex].insert(TRANSPARENCY_PROP, val.toDouble());
1977
1978       } else if(paramNameStr == DISPLAY_MODE_PROP) {
1979         aListOfMap[viewIndex].insert( DISPLAY_MODE_PROP, val.toInt());
1980
1981       } else if(paramNameStr == ISOS_PROP) {
1982         aListOfMap[viewIndex].insert( ISOS_PROP, val);
1983
1984       } else if(paramNameStr == COLOR_PROP) {
1985         QStringList rgb = val.split(DIGIT_SEPARATOR);
1986         if(rgb.count() == 3) {
1987           QColor c(int(rgb[0].toDouble()*255), int(rgb[1].toDouble()*255), int(rgb[2].toDouble()*255));
1988           aListOfMap[viewIndex].insert( COLOR_PROP, c);
1989         }
1990       } else if(paramNameStr == VECTOR_MODE_PROP) {
1991         aListOfMap[viewIndex].insert( VECTOR_MODE_PROP, val.toInt());
1992
1993       }  else if(paramNameStr == DEFLECTION_COEFF_PROP) {
1994         aListOfMap[viewIndex].insert( DEFLECTION_COEFF_PROP, val.toDouble());
1995       }  else if(paramNameStr == MARKER_TYPE_PROP) {
1996         aListOfMap[viewIndex].insert( MARKER_TYPE_PROP, val);
1997       }
1998
1999     } // for names/parameters iterator
2000
2001     QList<SUIT_ViewManager*> lst = getApp()->viewManagers();
2002
2003     for (int index = 0; index < aListOfMap.count(); index++) {
2004
2005       appStudy->setObjectPropMap(index, entry, aListOfMap[index]);
2006
2007       //Get Visibility property of the current PropMap
2008       if (aListOfMap[index].value(VISIBILITY_PROP) == 1) {
2009         SUIT_ViewManager* vman = lst.at(index);
2010         SUIT_ViewModel* vmodel = vman->getViewModel();
2011         displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
2012       }
2013     }
2014
2015   } // for entries iterator
2016
2017   // update all VTK and OCC views
2018   QList<SUIT_ViewManager*> lst;
2019   getApp()->viewManagers(lst);
2020   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
2021     SUIT_ViewModel* vmodel = (*it)->getViewModel();
2022     if (!vmodel)
2023       continue;
2024     if (vmodel->getType() == SVTK_Viewer::Type()) {
2025       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
2026       vtkView->getRenderer()->ResetCameraClippingRange();
2027       vtkView->Repaint();
2028     }
2029     else if (vmodel->getType() == SOCC_Viewer::Type()) {
2030       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2031       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
2032       if (occVMod)
2033         occVMod->Repaint();
2034     }
2035   }
2036 }
2037
2038 void GeometryGUI::onViewAboutToShow()
2039 {
2040   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
2041   QAction* a = action( GEOMOp::OpSwitchVectors );
2042   if ( window ) {
2043     a->setEnabled(true);
2044     bool vmode = window->property("VectorsMode").toBool();
2045     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
2046   } else {
2047     a->setText ( tr("MEN_VECTOR_MODE_ON") );
2048     a->setEnabled(false);
2049   }
2050 }
2051
2052 /*!
2053   Rename object by entry.
2054   \param entry entry of the object
2055   \param name new name of the object
2056   \brief Return \c true if rename operation finished successfully, \c false otherwise.
2057 */
2058 bool GeometryGUI::renameObject( const QString& entry, const QString& name) {
2059
2060   bool appRes = SalomeApp_Module::renameObject(entry,name);
2061   if( !appRes )
2062     return false;
2063
2064   bool result = false;
2065
2066   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
2067   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
2068
2069   if(!appStudy)
2070     return result;
2071
2072   _PTR(Study) aStudy = appStudy->studyDS();
2073
2074   if(!aStudy)
2075     return result;
2076
2077   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
2078   _PTR(GenericAttribute) anAttr;
2079   if ( obj ) {
2080     if ( obj->FindAttribute(anAttr, "AttributeName") ) {
2081       _PTR(AttributeName) aName (anAttr);
2082
2083       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
2084       if (!CORBA::is_nil(anObj)) {
2085         aName->SetValue( name.toLatin1().data() ); // rename the SObject
2086         anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
2087         result = true;
2088       }
2089     }
2090   }
2091   return result;
2092 }