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