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