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