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