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   int advancedTbId = createTool( tr( "TOOL_ADVANCED" ) );
979   //@@ insert new functions before this line @@//
980
981   // ---- create popup menus --------------------------
982
983   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
984   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
985
986   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
987   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
988
989   QString autoColorPrefix =
990     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
991
992   QtxPopupMgr* mgr = popupMgr();
993   mgr->insert( action(  GEOMOp::OpRename ), -1, -1 );  // rename
994   mgr->setRule( action( GEOMOp::OpRename ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
995   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
996   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
997   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
998   mgr->setRule( action( GEOMOp::OpGroupCreatePopup ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
999   mgr->insert( action(  GEOMOp::OpShowChildren ), -1, -1 ); // show children
1000   mgr->setRule( action( GEOMOp::OpShowChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1001   mgr->insert( action(  GEOMOp::OpHideChildren ), -1, -1 ); // hide children
1002   mgr->setRule( action( GEOMOp::OpHideChildren ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1003   mgr->insert( action(  GEOMOp::OpGroupEdit ), -1, -1 );  // edit group
1004   mgr->setRule( action( GEOMOp::OpGroupEdit ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1005   mgr->insert( separator(), -1, -1 );     // -----------
1006   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1007   mgr->insert( action(  GEOMOp::OpWireframe ), dispmodeId, -1 ); // wireframe
1008   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1009   mgr->setRule( action( GEOMOp::OpWireframe ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1010   mgr->insert( action(  GEOMOp::OpShading ), dispmodeId, -1 ); // shading
1011   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1012   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1013   mgr->insert( separator(), dispmodeId, -1 );
1014   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
1015   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1016   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1017   mgr->insert( separator(), -1, -1 );     // -----------
1018   mgr->insert( action(  GEOMOp::OpColor ), -1, -1 ); // color
1019   mgr->setRule( action( GEOMOp::OpColor ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1020   mgr->insert( action(  GEOMOp::OpTransparency ), -1, -1 ); // transparency
1021   mgr->setRule( action( GEOMOp::OpTransparency ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1022   mgr->insert( action(  GEOMOp::OpIsos ), -1, -1 ); // isos
1023   mgr->setRule( action( GEOMOp::OpIsos ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1024   mgr->insert( action(  GEOMOp::OpDeflection ), -1, -1 ); // deflection
1025   mgr->setRule( action( GEOMOp::OpDeflection ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1026   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
1027   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg( GEOM_POINT ), QtxPopupMgr::VisibleRule );
1028   mgr->insert( separator(), -1, -1 );     // -----------
1029   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
1030   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1031   mgr->insert( action(  GEOMOp::OpNoAutoColor ), -1, -1 ); // disable auto color
1032   mgr->setRule( action( GEOMOp::OpNoAutoColor ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1033   mgr->insert( separator(), -1, -1 );     // -----------
1034
1035   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1036           onlyComponent = "((type='Component') and selcount=1)",
1037           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1038           types = "'Shape' 'Group'";
1039
1040   mgr->insert( action(  GEOMOp::OpShow ), -1, -1 ); // display
1041   mgr->setRule( action( GEOMOp::OpShow ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1042
1043   mgr->insert( action(  GEOMOp::OpHide ), -1, -1 ); // erase
1044   mgr->setRule( action( GEOMOp::OpHide ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1045
1046   mgr->insert( action(  GEOMOp::OpHideAll ), -1, -1 ); // erase All
1047   mgr->setRule( action( GEOMOp::OpHideAll ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1048
1049   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1050
1051   int selectolnyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1052   mgr->insert( action(GEOMOp::OpSelectVertex),   selectolnyId, -1);                                  //Vertex
1053   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly, QtxPopupMgr::VisibleRule);
1054   mgr->setRule(action(GEOMOp::OpSelectVertex),   selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1055   mgr->insert( action(GEOMOp::OpSelectEdge),     selectolnyId, -1);                                  //Edge
1056   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly, QtxPopupMgr::VisibleRule);
1057   mgr->setRule(action(GEOMOp::OpSelectEdge),     selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1058   mgr->insert( action(GEOMOp::OpSelectWire),     selectolnyId, -1);                                  //Wire
1059   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly, QtxPopupMgr::VisibleRule);
1060   mgr->setRule(action(GEOMOp::OpSelectWire),     selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1061   mgr->insert( action(GEOMOp::OpSelectFace),     selectolnyId, -1);                                  //Face
1062   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly, QtxPopupMgr::VisibleRule);
1063   mgr->setRule(action(GEOMOp::OpSelectFace),     selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1064   mgr->insert( action(GEOMOp::OpSelectShell),    selectolnyId, -1);                                  //Shell
1065   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly, QtxPopupMgr::VisibleRule);
1066   mgr->setRule(action(GEOMOp::OpSelectShell),    selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1067   mgr->insert( action(GEOMOp::OpSelectSolid),    selectolnyId, -1);                                  //Solid
1068   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly, QtxPopupMgr::VisibleRule);
1069   mgr->setRule(action(GEOMOp::OpSelectSolid),    selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1070   mgr->insert( action(GEOMOp::OpSelectCompound), selectolnyId, -1);                                  //Compound
1071   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly, QtxPopupMgr::VisibleRule);
1072   mgr->setRule(action(GEOMOp::OpSelectCompound), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1073   mgr->insert( separator(), selectolnyId, -1);
1074   mgr->insert( action(GEOMOp::OpSelectAll),      selectolnyId, -1);                                  //Clear selection filter
1075   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly, QtxPopupMgr::VisibleRule);
1076   mgr->setRule(action(GEOMOp::OpSelectAll),      selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1077   mgr->insert( action(GEOMOp::OpShowOnly ), -1, -1 ); // display only
1078   mgr->setRule(action(GEOMOp::OpShowOnly ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1079   mgr->insert( separator(), -1, -1 );
1080
1081   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1082 }
1083
1084 //=======================================================================
1085 // function : GeometryGUI::activateModule()
1086 // purpose  : Called when GEOM module is activated
1087 //=======================================================================
1088 bool GeometryGUI::activateModule( SUIT_Study* study )
1089 {
1090   if ( CORBA::is_nil( myComponentGeom ) )
1091     return false;
1092
1093   bool res = SalomeApp_Module::activateModule( study );
1094
1095   if ( !res )
1096     return false;
1097
1098   setMenuShown( true );
1099   setToolShown( true );
1100
1101   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1102           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1103
1104   // Reset actions accelerator keys
1105   action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
1106   action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
1107   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
1108   action(GEOMOp::OpRename)->setEnabled( true ); // Rename: Key_F2
1109
1110   GUIMap::Iterator it;
1111   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1112     it.value()->activate( application()->desktop() );
1113
1114   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1115
1116   SUIT_ViewManager* vm;
1117   ViewManagerList OCCViewManagers, VTKViewManagers;
1118
1119   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1120   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1121   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1122     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1123
1124   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1125   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1126   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1127     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1128
1129   //NPAL 19674
1130   SALOME_ListIO selected;
1131   sm->selectedObjects( selected );
1132   sm->clearSelected();
1133   
1134   // disable OCC selectors
1135   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1136   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1137   while ( itOCCSel.hasNext() )
1138     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1139       sr->setEnabled(true);
1140
1141   // disable VTK selectors
1142   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1143   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1144   while ( itVTKSel.hasNext() )
1145     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1146       sr->setEnabled(true);
1147
1148   sm->setSelectedObjects( selected, true );   //NPAL 19674
1149
1150   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1151   if ( viewMenu )
1152     connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1153
1154   return true;
1155 }
1156
1157
1158 //=======================================================================
1159 // function : GeometryGUI::deactivateModule()
1160 // purpose  : Called when GEOM module is deactivated
1161 //=======================================================================
1162 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1163 {
1164   QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1165   if ( viewMenu )
1166     disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1167
1168   setMenuShown( false );
1169   setToolShown( false );
1170
1171   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1172              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1173
1174   EmitSignalCloseAllDialogs();
1175
1176   GUIMap::Iterator it;
1177   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1178     it.value()->deactivate();
1179
1180   // Unset actions accelerator keys
1181   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
1182   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
1183   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
1184   action(GEOMOp::OpRename)->setEnabled( false ); // Rename: Key_F2
1185
1186   qDeleteAll(myOCCSelectors);
1187   myOCCSelectors.clear();
1188   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1189
1190   qDeleteAll(myVTKSelectors);
1191   myVTKSelectors.clear();
1192   getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1193
1194   return SalomeApp_Module::deactivateModule( study );
1195 }
1196
1197 //=======================================================================
1198 // function : onWindowActivated()
1199 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1200 //=======================================================================
1201 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1202 {
1203   if ( !win )
1204     return;
1205
1206   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1207   //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1208
1209   // disable non-OCC viewframe menu commands
1210 //  action( GEOMOp::Op2dSketcher )->setEnabled( ViewOCC ); // SKETCHER
1211   action( GEOMOp::OpSuppressFaces )->setEnabled( ViewOCC ); // SuppressFace
1212   action( GEOMOp::OpSuppressHoles )->setEnabled( ViewOCC ); // SuppressHole
1213   action( GEOMOp::OpCloseContour )->setEnabled( ViewOCC ); // CloseContour
1214   action( GEOMOp::OpRemoveIntWires )->setEnabled( ViewOCC ); // RemoveInternalWires
1215   action( GEOMOp::OpAddPointOnEdge )->setEnabled( ViewOCC ); // AddPointOnEdge
1216 //  action( GEOMOp::OpFreeBoundaries )->setEnabled( ViewOCC ); // Free boundaries
1217
1218   action( GEOMOp::OpGroupCreate )->setEnabled( ViewOCC ); // Create Group
1219   action( GEOMOp::OpGroupEdit )->setEnabled( ViewOCC ); // Edit Group
1220
1221   action( GEOMOp::OpMultiTransform )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1222 }
1223
1224 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1225 {
1226   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1227   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1228 }
1229
1230 void GeometryGUI::viewManagers( QStringList& lst ) const
1231 {
1232   lst.append( OCCViewer_Viewer::Type() );
1233 }
1234
1235 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1236 {
1237   if ( vm->getType() == OCCViewer_Viewer::Type() )
1238   {
1239     qDebug( "connect" );
1240     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1241              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1242     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1243              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1244     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1245              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1246
1247     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1248     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1249
1250     // disable OCC selectors
1251     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1252     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1253     while ( itOCCSel.hasNext() )
1254       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1255         sr->setEnabled(true);
1256   }
1257   else if ( vm->getType() == SVTK_Viewer::Type() )
1258   {
1259     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1260     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1261
1262     // disable VTK selectors
1263     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1264     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1265     while ( itVTKSel.hasNext() )
1266       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1267         sr->setEnabled(true);
1268   }
1269 }
1270
1271 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1272 {
1273   SUIT_ViewModel* viewer = vm->getViewModel();
1274   if ( vm->getType() == OCCViewer_Viewer::Type() )
1275   {
1276     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1277     while ( itOCCSel.hasNext() )
1278       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1279         if ( sr->viewer() == viewer )
1280         {
1281           delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1282           break;
1283         }
1284   }
1285   if ( vm->getType() == SVTK_Viewer::Type() )
1286   {
1287     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1288     while ( itVTKSel.hasNext() )
1289       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1290         if ( sr->viewer() == viewer )
1291         {
1292           delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1293           break;
1294         }
1295   }
1296 }
1297
1298 QString GeometryGUI::engineIOR() const
1299 {
1300   if ( !CORBA::is_nil( GetGeomGen() ) )
1301     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1302   return "";
1303 }
1304
1305 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture( SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight )
1306 {
1307   theWidth = theHeight = 0;
1308   Handle(Graphic3d_HArray1OfBytes) aTexture;
1309   if ( theStudy ) {
1310     TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1311     aTexture = aTextureMap[ theId ];
1312     if ( aTexture.IsNull() ) {
1313       GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1314       if ( !aInsOp->_is_nil() ) {
1315         CORBA::Long aWidth, aHeight;
1316         SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1317         if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1318           theWidth  = aWidth;
1319           theHeight = aHeight;
1320           aTexture  = new Graphic3d_HArray1OfBytes( 1, aStream->length() );
1321           for ( int i = 0; i < aStream->length(); i++ )
1322             aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1323           aTextureMap[ theId ] = aTexture;
1324         }
1325       }
1326     }
1327   }
1328   return aTexture;
1329 }
1330
1331 LightApp_Selection* GeometryGUI::createSelection() const
1332 {
1333   return new GEOMGUI_Selection();
1334 }
1335
1336 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1337 {
1338   SalomeApp_Module::contextMenuPopup(client, menu, title);
1339
1340   SALOME_ListIO lst;
1341   getApp()->selectionMgr()->selectedObjects(lst);
1342   if (lst.Extent() < 1)
1343     return;
1344
1345   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1346   _PTR(Study) study = appStudy->studyDS();
1347
1348   bool isImported = true;
1349   SALOME_ListIteratorOfListIO anIt (lst);
1350   for (; anIt.More() && isImported; anIt.Next()) {
1351     Handle(SALOME_InteractiveObject) io = anIt.Value();
1352     _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1353     if (aSObj) {
1354       if (lst.Extent() == 1) {
1355         // Set context menu title
1356         if (client == "OCCViewer" || client == "VTKViewer")
1357           title = QString(aSObj->GetName().c_str());
1358       }
1359
1360       CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1361       GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1362       if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1363         isImported = false;
1364     } else {
1365       isImported = false;
1366     }
1367   }
1368
1369   if (isImported) {
1370     menu->addAction(action(GEOMOp::OpReimport)); // Reload imported shape
1371   }
1372 }
1373
1374 void GeometryGUI::createPreferences()
1375 {
1376   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1377
1378   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1379   setPreferenceProperty( genGroup, "columns", 2 );
1380
1381   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1382                                 LightApp_Preferences::Selector, 
1383                                 "Geometry", "display_mode" );
1384
1385   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1386                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1387
1388   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1389                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1390
1391   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1392                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1393
1394   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1395                  LightApp_Preferences::Color, "Geometry", "line_color" );
1396
1397   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1398                  LightApp_Preferences::Color, "Geometry", "point_color" );
1399
1400   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1401                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1402
1403   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1404                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1405
1406   int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup,
1407                             LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" );
1408
1409   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1410   setPreferenceProperty( VertexGroup, "columns", 2 );
1411
1412   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1413                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1414
1415   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1416                                    LightApp_Preferences::Selector, "Geometry", "marker_scale" );
1417
1418   // Set property for default display mode
1419   QStringList aModesList;
1420   aModesList.append( tr("MEN_WIREFRAME") );
1421   aModesList.append( tr("MEN_SHADING") );
1422
1423   QList<QVariant> anIndexesList;
1424   anIndexesList.append(0);
1425   anIndexesList.append(1);
1426
1427   setPreferenceProperty( dispmode, "strings", aModesList );
1428   setPreferenceProperty( dispmode, "indexes", anIndexesList );
1429
1430   // Set property for step value for spinboxes
1431   setPreferenceProperty( step, "min", 1 );
1432   setPreferenceProperty( step, "max", 10000 );
1433   setPreferenceProperty( step, "precision", 3 );
1434
1435   // Set property for deflection value for spinboxes
1436   setPreferenceProperty( defl, "min", DEFLECTION_MIN );
1437   setPreferenceProperty( defl, "max", 1.0 );
1438   setPreferenceProperty( defl, "step", 1.0e-04 );
1439   setPreferenceProperty( defl, "precision", 6 );
1440
1441   // Set property vertex marker type
1442   QList<QVariant> aMarkerTypeIndicesList;
1443   QList<QVariant> aMarkerTypeIconsList;
1444
1445   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1446   for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
1447     QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
1448     QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
1449     aMarkerTypeIndicesList << (i-1);
1450     aMarkerTypeIconsList << pixmap;
1451   }
1452
1453   setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
1454   setPreferenceProperty( typeOfMarker, "icons",   aMarkerTypeIconsList );
1455
1456   // Set property for vertex marker scale
1457   QList<QVariant> aMarkerScaleIndicesList;
1458   QStringList     aMarkerScaleValuesList;
1459
1460   for ( int i = GEOM::MS_10; i <= GEOM::MS_70; i++ ) {
1461     aMarkerScaleIndicesList << i;
1462     aMarkerScaleValuesList  << QString::number( (i-(int)GEOM::MS_10)*0.5 + 1.0 );
1463   }
1464
1465   setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
1466   setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
1467 }
1468
1469 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1470 {
1471   if (section == "Geometry") {
1472     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1473     if (param == QString("SettingsGeomStep")) {
1474       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1475       EmitSignalDefaultStepValueChanged(spin_step);
1476     }
1477   }
1478 }
1479
1480 LightApp_Displayer* GeometryGUI::displayer()
1481 {
1482   if( !myDisplayer )
1483     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1484   return myDisplayer;
1485 }
1486
1487 void GeometryGUI::setLocalSelectionMode(const int mode)
1488 {
1489   myLocalSelectionMode = mode;
1490 }
1491 int GeometryGUI::getLocalSelectionMode() const
1492 {
1493   return myLocalSelectionMode;
1494 }
1495
1496 const char gSeparator = '_'; // character used to separate parameter names
1497 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1498
1499 /*!
1500  * \brief Store visual parameters
1501  *
1502  * This method is called just before the study document is saved.
1503  * Store visual parameters in AttributeParameter attribue(s)
1504  */
1505 void GeometryGUI::storeVisualParameters (int savePoint)
1506 {
1507   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1508   if (!appStudy || !appStudy->studyDS())
1509     return;
1510   _PTR(Study) studyDS = appStudy->studyDS();
1511
1512   // componentName is used for encoding of entries when storing them in IParameters
1513   std::string componentName = myComponentGeom->ComponentDataType();
1514   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1515   //if (!aSComponent) return;
1516
1517   // IParameters
1518   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1519                                                              componentName.c_str(),
1520                                                              savePoint);
1521   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1522
1523   // viewers counters are used for storing view_numbers in IParameters
1524   int vtkViewers(0), occViewers(0);
1525
1526   QList<SUIT_ViewManager*> lst;
1527   QList<SUIT_ViewManager*>::Iterator it;
1528
1529   // main cycle to store parameters of displayed objects
1530   lst.clear();
1531   vtkViewers = occViewers = 0;
1532   getApp()->viewManagers(lst);
1533   for (it = lst.begin(); it != lst.end(); it++)
1534   {
1535     SUIT_ViewManager* vman = *it;
1536     QString vType = vman->getType();
1537
1538     // saving VTK actors properties
1539     if (vType == SVTK_Viewer::Type())
1540     {
1541       QVector<SUIT_ViewWindow*> views = vman->getViews();
1542       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1543       {
1544         if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
1545         {
1546           vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1547           allActors->InitTraversal();
1548           while (vtkActor* actor = allActors->GetNextActor())
1549           {
1550             if (actor->GetVisibility()) // store only visible actors
1551             {
1552               GEOM_Actor* aGeomActor = 0;
1553               if (actor->IsA("GEOM_Actor"))
1554                 aGeomActor = GEOM_Actor::SafeDownCast(actor);
1555               if (aGeomActor && aGeomActor->hasIO())
1556               {
1557                 Handle(SALOME_InteractiveObject) io = aGeomActor->getIO();
1558                 if (io->hasEntry())
1559                 {
1560                   // entry is "encoded" = it does NOT contain component adress, since it is a
1561                   // subject to change on next component loading
1562                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1563
1564                   std::string param, occParam = vType.toLatin1().data();
1565                   occParam += gSeparator;
1566                   occParam += QString::number(vtkViewers).toLatin1().data();
1567                   occParam += gSeparator;
1568
1569                   param = occParam + "Visibility";
1570                   ip->setParameter(entry, param, "On");
1571
1572                   param = occParam + "DisplayMode";
1573                   ip->setParameter(entry, param, QString::number
1574                                    (aGeomActor->getDisplayMode()).toLatin1().data());
1575
1576                   vtkFloatingPointType r, g, b;
1577                   aGeomActor->GetColor(r, g, b);
1578                   QString colorStr = QString::number(r);
1579                   colorStr += gDigitsSep; colorStr += QString::number(g);
1580                   colorStr += gDigitsSep; colorStr += QString::number(b);
1581                   param = occParam + "Color";
1582                   ip->setParameter(entry, param, colorStr.toLatin1().data());
1583
1584                   param = occParam + "Opacity";
1585                   ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data());
1586
1587                   int nbUIso(0), nbVIso(0);
1588                   aGeomActor->GetNbIsos(nbUIso,nbVIso);
1589                   QString isosStr = QString::number(nbUIso);
1590                   isosStr += gDigitsSep;
1591                   isosStr += QString::number(nbVIso);
1592                   param = occParam + "Isos";
1593                   ip->setParameter(entry, param, isosStr.toLatin1().data());
1594                 } // if (io->hasEntry())
1595               } // GEOM_Actor && hasIO
1596             } // isVisible
1597           } // while.. actors traversal
1598         } // if (vtkView)
1599       } // for (views)
1600       vtkViewers++;
1601     } // if (SVTK view model)
1602     else if (vType == SOCC_Viewer::Type()) // processing OCC viewers
1603     {
1604       QVector<SUIT_ViewWindow*> views = vman->getViews();
1605       for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1606       {
1607         SOCC_ViewWindow* occView = dynamic_cast<SOCC_ViewWindow*>(views[i]);
1608         if (occView)
1609         {
1610           //Handle(AIS_InteractiveContext) ic =
1611           //  ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext();
1612           OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel());
1613           //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer();
1614           Handle(AIS_InteractiveContext) ic = viewModel->getAISContext();
1615
1616           AIS_ListOfInteractive aList;
1617           ic->DisplayedObjects(aList);
1618
1619           AIS_ListIteratorOfListOfInteractive ite (aList);
1620           for (; ite.More(); ite.Next())
1621           {
1622             if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
1623             {
1624               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1625               if (aSh->hasIO())
1626               {
1627                 Handle(SALOME_InteractiveObject) io =
1628                   Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1629                 if (io->hasEntry())
1630                 {
1631                   // entry is "encoded": it does NOT contain component adress,
1632                   // since it is a subject to change on next component loading
1633                   std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1634
1635                   std::string param, occParam = vType.toLatin1().data();
1636                   occParam += gSeparator;
1637                   occParam += QString::number(occViewers).toLatin1().data();
1638                   occParam += gSeparator;
1639
1640                   // Visibility
1641                   param = occParam + "Visibility";
1642                   ip->setParameter(entry, param, "On");
1643
1644                   // DisplayMode
1645                   param = occParam + "DisplayMode";
1646                   int dm = aSh->DisplayMode();
1647                   ip->setParameter(entry, param, QString::number(dm).toLatin1().data());
1648
1649                   // Color
1650                   // is a property of GEOM_Object, it is stored by GEOM engine
1651
1652                   // Transparency
1653                   param = occParam + "Transparency";
1654                   ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data());
1655
1656                   // Isos
1657                   Handle(AIS_Drawer) aDrawer = aSh->Attributes();
1658                   int nbUIso = aDrawer->UIsoAspect()->Number();
1659                   int nbVIso = aDrawer->VIsoAspect()->Number();
1660                   QString isosStr = QString::number(nbUIso);
1661                   isosStr += gDigitsSep;
1662                   isosStr += QString::number(nbVIso);
1663                   param = occParam + "Isos";
1664                   ip->setParameter(entry, param, isosStr.toLatin1().data());
1665                 } // if (io->hasEntry())
1666               } // if (io)
1667             } // if (GEOM_AISShape)
1668           } // for (AIS_ListOfInteractive)
1669         } // if ( occView )
1670       } // for ( views )
1671       occViewers++;
1672     } // if (SOCC view model)
1673     else
1674     {
1675       // unknown viewer type
1676     }
1677   } // for (viewManagers)
1678 }
1679
1680 /*!
1681  * \brief Restore visual parameters
1682  *
1683  * This method is called after the study document is opened.
1684  * Restore visual parameters from AttributeParameter attribue(s)
1685  */
1686 void GeometryGUI::restoreVisualParameters (int savePoint)
1687 {
1688   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1689   if (!appStudy || !appStudy->studyDS())
1690     return;
1691   _PTR(Study) studyDS = appStudy->studyDS();
1692
1693   // componentName is used for encoding of entries when storing them in IParameters
1694   std::string componentName = myComponentGeom->ComponentDataType();
1695   //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1696   //if (!aSComponent) return;
1697
1698   // IParameters
1699   _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1700                                                              componentName.c_str(),
1701                                                              savePoint);
1702   _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1703
1704   std::vector<std::string> entries = ip->getEntries();
1705
1706   for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1707   {
1708     // entry is a normal entry - it should be "decoded" (setting base adress of component)
1709     QString entry (ip->decodeEntry(*entIt).c_str());
1710
1711     // Check that the entry corresponds to a real object in the Study
1712     // as the object may be deleted or modified after the visual state is saved.
1713     _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1714     if (!so) continue; //Skip the not existent entry
1715
1716     std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1717     std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1718
1719     std::vector<std::string>::iterator namesIt = paramNames.begin();
1720     std::vector<std::string>::iterator valuesIt = paramValues.begin();
1721
1722     // actors are stored in a map after displaying of them for
1723     // quicker access in the future: map < viewID to actor >
1724     NCollection_DataMap<int, GEOM_Actor*          > vtkActors;
1725     NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1726
1727     for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1728     {
1729       // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1730       // '_' is used as separator and should not be used in viewer type or parameter names.
1731       QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
1732       if (lst.size() != 3)
1733         continue;
1734
1735       QString viewerTypStr = lst[0];
1736       QString viewIndexStr = lst[1];
1737       QString paramNameStr = lst[2];
1738
1739       bool ok;
1740       int viewIndex = viewIndexStr.toUInt(&ok);
1741       if (!ok) // bad conversion of view index to integer
1742         continue;
1743
1744       // viewers
1745       if (viewerTypStr == SVTK_Viewer::Type())
1746       {
1747         GEOM_Actor* vActor = 0;
1748         if (vtkActors.IsBound(viewIndex))
1749           vActor = vtkActors.Find(viewIndex);
1750
1751         if (paramNameStr == "Visibility")
1752         {
1753           if (!vActor && displayer())
1754           {
1755             QList<SUIT_ViewManager*> lst;
1756             getApp()->viewManagers(viewerTypStr, lst);
1757
1758             // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1759             if (viewIndex >= 0 && viewIndex < lst.count()) {
1760               SUIT_ViewManager* vman = lst.at(viewIndex);
1761               SUIT_ViewModel* vmodel = vman->getViewModel();
1762               // SVTK view model can be casted to SALOME_View
1763               displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1764
1765               // store displayed actor in a temporary map for quicker
1766               // access later when restoring other parameters
1767               SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1768               vtkRenderer* Renderer = vtkView->getRenderer();
1769               vtkActorCollection* theActors = Renderer->GetActors();
1770               theActors->InitTraversal();
1771               bool isFound = false;
1772               vtkActor *ac = theActors->GetNextActor();
1773               for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
1774                 if (ac->IsA("GEOM_Actor")) {
1775                   GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac);
1776                   if (aGeomAc->hasIO()) {
1777                     Handle(SALOME_InteractiveObject) io =
1778                       Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
1779                     if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1780                       isFound = true;
1781                       vtkActors.Bind(viewIndex, aGeomAc);
1782                     }
1783                   }
1784                 }
1785               }
1786             }
1787           }
1788         } // if (paramNameStr == "Visibility")
1789         else
1790         {
1791           // the rest properties "work" with GEOM_Actor
1792           if (vActor)
1793           {
1794             QString val ((*valuesIt).c_str());
1795
1796             if (paramNameStr == "DisplayMode") {
1797               vActor->setDisplayMode(val.toInt());
1798             }
1799             else if (paramNameStr == "Color") {
1800               QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
1801               if (colors.count() == 3)
1802                 vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat());
1803             }
1804             else if (paramNameStr == "Opacity") {
1805               vActor->SetOpacity(val.toFloat());
1806             }
1807             else if (paramNameStr == "Isos") {
1808               QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1809               if (isos.count() == 2) {
1810                 int aIsos[2] = {isos[0].toInt(), isos[1].toInt()};
1811                 vActor->SetNbIsos(aIsos);
1812               }
1813             }
1814           }
1815         } // other parameters than Visibility
1816       }
1817       else if (viewerTypStr == SOCC_Viewer::Type())
1818       {
1819         //Handle(AIS_InteractiveObject) occActor;
1820         Handle(GEOM_AISShape) occActor;
1821         if (occActors.IsBound(viewIndex))
1822           occActor = occActors.Find(viewIndex);
1823
1824         // ViewModel and InteractiveContext
1825         SOCC_Viewer* occVModel = 0;
1826         Handle(AIS_InteractiveContext) ic;
1827
1828         QList<SUIT_ViewManager*> lst;
1829         getApp()->viewManagers(viewerTypStr, lst);
1830
1831         // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager
1832         if (viewIndex >= 0 && viewIndex < lst.count()) {
1833           SUIT_ViewManager* vman = lst.at(viewIndex);
1834           SUIT_ViewModel* vmodel = vman->getViewModel();
1835           occVModel = dynamic_cast<SOCC_Viewer*>(vmodel);
1836           if (occVModel)
1837             ic = occVModel->getAISContext();
1838         }
1839
1840         if (ic.IsNull())
1841           continue;
1842
1843         if (paramNameStr == "Visibility")
1844         {
1845           if (occActor.IsNull() && displayer())
1846           {
1847             displayer()->Display(entry, true, occVModel);
1848
1849             // store displayed actor in a temporary map for quicker
1850             // access later when restoring other parameters
1851             AIS_ListOfInteractive aList;
1852             ic->DisplayedObjects(aList);
1853             bool isFound = false;
1854             AIS_ListIteratorOfListOfInteractive ite (aList);
1855             for (; ite.More() && !isFound; ite.Next()) {
1856               if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1857                 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1858                 if (aSh->hasIO()) {
1859                   Handle(SALOME_InteractiveObject) io =
1860                     Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1861                   if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1862                     isFound = true;
1863                     occActors.Bind(viewIndex, aSh);
1864                   }
1865                 }
1866               }
1867             }
1868           }
1869         } // if (paramNameStr == "Visibility")
1870         else
1871         {
1872           // the rest properties "work" with GEOM_AISShape
1873           if (!occActor.IsNull())
1874           {
1875             QString val ((*valuesIt).c_str());
1876
1877             if (paramNameStr == "DisplayMode") {
1878               ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false);
1879               //ic->Redisplay(occActor, Standard_False, Standard_True);
1880             }
1881             // Color is restored by the GEOM engine
1882             else if (paramNameStr == "Transparency") {
1883               ic->SetTransparency(occActor, val.toFloat(), false);
1884               ic->Redisplay(occActor, Standard_False, Standard_True);
1885             }
1886             else if (paramNameStr == "Isos") {
1887               QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1888               if (isos.count() == 2) {
1889                 Handle(AIS_Drawer) aDrawer = occActor->Attributes();
1890                 int nbUIso = isos[0].toInt();
1891                 int nbVIso = isos[1].toInt();
1892                 Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect();
1893                 Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect();
1894                 uIsoAspect->SetNumber(nbUIso);
1895                 vIsoAspect->SetNumber(nbVIso);
1896                 aDrawer->SetUIsoAspect(uIsoAspect);
1897                 aDrawer->SetVIsoAspect(vIsoAspect);
1898                 ic->SetLocalAttributes(occActor, aDrawer);
1899                 ic->Redisplay(occActor);
1900               }
1901             }
1902           }
1903         } // other parameters than Visibility
1904       }
1905       else
1906       {
1907         // unknown viewer type
1908       }
1909     } // for names/parameters iterator
1910   } // for entries iterator
1911
1912   // update all VTK and OCC views
1913   QList<SUIT_ViewManager*> lst;
1914   getApp()->viewManagers(lst);
1915   for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
1916     SUIT_ViewModel* vmodel = (*it)->getViewModel();
1917     if (!vmodel)
1918       continue;
1919     if (vmodel->getType() == SVTK_Viewer::Type()) {
1920       SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
1921       vtkView->getRenderer()->ResetCameraClippingRange();
1922       vtkView->Repaint();
1923     }
1924     else if (vmodel->getType() == SOCC_Viewer::Type()) {
1925       //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
1926       SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
1927       if (occVMod)
1928         occVMod->Repaint();
1929     }
1930   }
1931 }
1932
1933 void GeometryGUI::onViewAboutToShow()
1934 {
1935   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
1936   QAction* a = action( GEOMOp::OpSwitchVectors );
1937   if ( window ) {
1938     a->setEnabled(true);
1939     bool vmode = window->getCustomData("VectorsMode").toBool();
1940     a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
1941   } else {
1942     a->setText ( tr("MEN_VECTOR_MODE_ON") );
1943     a->setEnabled(false);
1944   }
1945 }