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