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