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