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