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