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