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