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