Salome HOME
da79dd19f48783954152b0eaea50c5fabb79fd06
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : GeometryGUI.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GeometryGUI.h"
30 #include "GEOMGUI_OCCSelector.h"
31 #include "GEOMGUI_Selection.h"
32
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ViewManager.h>
37
38 #include <OCCViewer_ViewWindow.h>
39 #include <OCCViewer_ViewPort3d.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewManager.h>
42
43 #include <VTKViewer_ViewWindow.h>
44 #include <SVTK_RenderWindowInteractor.h>
45 #include <SVTK_InteractorStyle.h>
46 #include <SVTK_ViewModel.h>
47 #include <VTKViewer_ViewManager.h>
48
49 #include <SalomeApp_Application.h>
50 #include <SalomeApp_SelectionMgr.h>
51 #include <SalomeApp_VTKSelector.h>
52 #include <SalomeApp_Study.h>
53 #include <SALOME_LifeCycleCORBA.hxx>
54 #include <SALOME_ListIO.hxx>
55
56 // External includes
57 #include <qfileinfo.h>
58 #include <qpainter.h>
59
60 #include <Prs3d_Drawer.hxx>
61 #include <Prs3d_IsoAspect.hxx>
62 #include <OSD_SharedLibrary.hxx>
63
64 #include <utilities.h>
65
66 #include <vtkCamera.h>
67 #include <vtkRenderer.h>
68
69 extern "C" {
70   Standard_EXPORT CAM_Module* createModule() {
71     return new GeometryGUI();
72   }
73 }
74
75 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil(); 
76
77 //=================================================================================
78 // class   : CustomItem
79 // purpose : Set Font to a text.
80 //=================================================================================
81 class CustomItem : public QCustomMenuItem
82 {
83 public:
84   CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
85   ~CustomItem() {}
86
87   void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
88   {
89     p->save();
90     p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
91     p->setPen( act ? cg.highlightedText() : cg.buttonText() );
92     p->setFont( myFont );
93     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
94     p->restore();
95   }
96
97   QSize sizeHint()
98   {
99     return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
100   }
101
102   bool fullSpan() const
103   {
104     return true;
105   }
106
107 private:
108   QString myString;
109   QFont   myFont;
110 };
111
112 //=======================================================================
113 // function : GeometryGUI::GeometryGUI()
114 // purpose  : Constructor
115 //=======================================================================
116 GeometryGUI::GeometryGUI() :
117   SalomeApp_Module( "GEOM" )
118 {
119   if ( CORBA::is_nil( myComponentGeom ) )
120   { 
121     SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
122     Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
123     myComponentGeom   = GEOM::GEOM_Gen::_narrow( comp );
124   }
125
126   myState           = -1;
127   myActiveDialogBox = 0;
128   myFatherior       = "";
129
130   gp_Pnt origin = gp_Pnt(0., 0., 0.);
131   gp_Dir direction = gp_Dir(0., 0., 1.);
132   myWorkingPlane = gp_Ax3(origin, direction);
133
134   myOCCSelectors.setAutoDelete( true );
135   myVTKSelectors.setAutoDelete( true );
136 }
137
138 //=======================================================================
139 // function : GeometryGUI::~GeometryGUI()
140 // purpose  : Destructor
141 //=======================================================================
142 GeometryGUI::~GeometryGUI()
143 {
144 }
145
146 //=======================================================================
147 // function : GeometryGUI::getLibrary()
148 // purpose  : get or load GUI library by name [ internal ]
149 //=======================================================================
150 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
151 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
152 {
153   if ( !myGUIMap.contains( libraryName ) ) {
154     // try to load library if it is not loaded yet
155     QCString libs;
156     if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
157       QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
158       for( int i = dirList.count()-1; i >= 0; i-- ) {
159         QString dir = dirList[ i ];
160         QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
161         if( fi.exists() ) {
162           OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
163           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
164           if( !res ) {
165             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
166             continue; // continue search further
167           }
168           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
169           if ( osdF != NULL ) {
170             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
171             GEOMGUI* libGUI = (*func)(this);
172             if ( libGUI ) {
173               myGUIMap[ libraryName ] = libGUI;
174               break; // found and loaded!
175             }
176           }
177         }
178       }
179     }
180   }
181   if ( myGUIMap.contains( libraryName ) )
182     // library is successfully loaded
183     return myGUIMap[ libraryName ];
184   return 0;
185 }
186
187 //=======================================================================
188 // function : GeometryGUI::ActiveWorkingPlane()
189 // purpose  : Activate Working Plane View
190 //=======================================================================
191 void GeometryGUI::ActiveWorkingPlane()
192 {
193   gp_Dir DZ = myWorkingPlane.Direction();
194   gp_Dir DY = myWorkingPlane.YDirection();
195
196   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
197   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
198   bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
199
200   if( ViewOCC ) {
201     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
202     if ( vw ) {
203       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
204
205       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
206       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
207
208       vw->onViewFitAll();
209     }
210   }
211   else if( ViewVTK ) {
212     VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
213     if ( vw ) {
214       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
215
216       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
217       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
218       camera->SetFocalPoint(0,0,0);
219
220       vw->onFitAll();
221     }
222   }
223 }
224
225 //=======================================================================
226 // function : GeometryGUI::SetActiveDialogBox()
227 // purpose  : Set active dialog box
228 //=======================================================================
229 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
230 {
231   myActiveDialogBox = (QDialog*)aDlg;
232 }
233
234 //=======================================================================
235 // function : GeometryGUI::EmitSignalDeactivateDialog()
236 // purpose  : Emit a signal to deactivate the active dialog Box
237 //=======================================================================
238 void GeometryGUI::EmitSignalDeactivateDialog()
239 {
240   emit SignalDeactivateActiveDialog();
241 }
242
243 //=======================================================================
244 // function : GeometryGUI::EmitSignalCloseAllDialogs()
245 // purpose  : Emit a signal to close all non modal dialogs box
246 //=======================================================================
247 void GeometryGUI::EmitSignalCloseAllDialogs()
248 {
249   emit SignalCloseAllDialogs();
250 }
251
252 //=======================================================================
253 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
254 // purpose  : Emit a signal to inform that default real spin box step has
255 //            been changed
256 //=======================================================================
257 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
258 {
259   emit SignalDefaultStepValueChanged(newVal);
260 }
261
262 //=======================================================================
263 // function : GeometryGUI::OnGUIEvent()
264 // purpose  : common slot for all menu/toolbar actions
265 //=======================================================================
266 void GeometryGUI::OnGUIEvent()
267 {
268   const QObject* obj = sender();
269   if ( !obj || !obj->inherits( "QAction" ) )
270     return;
271   int id = actionId((QAction*)obj);
272   if ( id != -1 )
273     OnGUIEvent( id );
274 }
275
276 //=======================================================================
277 // function : GeometryGUI::OnGUIEvent()
278 // purpose  : manage all events on GUI [static]
279 //=======================================================================
280 void GeometryGUI::OnGUIEvent( int id )
281 {
282   SUIT_Desktop* desk = application()->desktop();
283   // check if current viewframe is of OCC type
284   SUIT_ViewWindow* window = desk->activeWindow();
285   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
286   bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
287   // if current viewframe is not of OCC and not of VTK type - return immediately
288   if( !ViewOCC && !ViewVTK )
289       return;
290
291   GEOMGUI* library = 0;
292   // try to get-or-load corresponding GUI library
293   if( id == 111  ||  // MENU FILE - IMPORT BREP
294       id == 112  ||  // MENU FILE - IMPORT IGES
295       id == 113  ||  // MENU FILE - IMPORT STEP
296       id == 121  ||  // MENU FILE - EXPORT BREP
297       id == 122  ||  // MENU FILE - EXPORT IGES
298       id == 123  ||  // MENU FILE - EXPORT STEP
299       id == 31   ||  // MENU EDIT - COPY
300       id == 33   ||  // MENU EDIT - DELETE
301       id == 411  ||  // MENU SETTINGS - ADD IN STUDY
302       id == 412  ||  // MENU SETTINGS - SHADING COLOR
303       id == 413  ||  // MENU SETTINGS - ISOS
304       id == 414  ||  // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
305       id == 5103 ||  // MENU TOOLS - CHECK GEOMETRY
306       id == 5104 ||  // MENU TOOLS - LOAD SCRIPT
307       id == 8032 ||  // POPUP VIEWER - COLOR
308       id == 8033 ||  // POPUP VIEWER - TRANSPARENCY
309       id == 8034 ||  // POPUP VIEWER - ISOS
310       id == 804  ||  // POPUP VIEWER - ADD IN STUDY
311       id == 901  ||  // OBJECT BROWSER - RENAME
312       id == 9024 ) { // OBJECT BROWSER - OPEN
313     //cout << "id " << id << " received" << endl;
314     library = getLibrary( "libGEOMToolsGUI.so" );
315   }
316   else if( id == 211  ||  // MENU VIEW - WIREFRAME/SHADING
317            id == 212  ||  // MENU VIEW - DISPLAY ALL
318            id == 213  ||  // MENU VIEW - DISPLAY ONLY
319            id == 214  ||  // MENU VIEW - ERASE ALL
320            id == 215  ||  // MENU VIEW - ERASE
321            id == 216  ||  // MENU VIEW - DISPLAY
322            id == 80311 ||  // POPUP VIEWER - WIREFRAME
323            id == 80312 ) { // POPUP VIEWER - SHADING
324     library = getLibrary( "libDisplayGUI.so" );
325   }
326   else if( id == 4011 ||  // MENU BASIC - POINT
327            id == 4012 ||  // MENU BASIC - LINE
328            id == 4013 ||  // MENU BASIC - CIRCLE
329            id == 4014 ||  // MENU BASIC - ELLIPSE
330            id == 4015 ||  // MENU BASIC - ARC
331            id == 4016 ||  // MENU BASIC - VECTOR
332            id == 4017 ||  // MENU BASIC - PLANE
333            id == 4018 ||  // MENU BASIC - WPLANE
334            id == 4019 ||  // MENU BASIC - CURVE
335            id == 4020 ) { // MENU BASIC - REPAIR
336     library = getLibrary( "libBasicGUI.so" );
337   }
338   else if( id == 4021 ||  // MENU PRIMITIVE - BOX
339            id == 4022 ||  // MENU PRIMITIVE - CYLINDER
340            id == 4023 ||  // MENU PRIMITIVE - SPHERE
341            id == 4024 ||  // MENU PRIMITIVE - TORUS
342            id == 4025 ) { // MENU PRIMITIVE - CONE
343     library = getLibrary( "libPrimitiveGUI.so" );
344   }
345   else if( id == 4031 ||  // MENU GENERATION - PRISM
346            id == 4032 ||  // MENU GENERATION - REVOLUTION
347            id == 4033 ||  // MENU GENERATION - FILLING
348            id == 4034 ) { // MENU GENERATION - PIPE
349     library = getLibrary( "libGenerationGUI.so" );
350   }
351   else if( id == 404 ||   // MENU ENTITY - SKETCHER
352            id == 407 ) {  // MENU ENTITY - EXPLODE
353     library = getLibrary( "libEntityGUI.so" );
354   }
355   else if( id == 4081 ||  // MENU BUILD - EDGE
356            id == 4082 ||  // MENU BUILD - WIRE
357            id == 4083 ||  // MENU BUILD - FACE
358            id == 4084 ||  // MENU BUILD - SHELL
359            id == 4085 ||  // MENU BUILD - SOLID
360            id == 4086 ) { // MENU BUILD - COMPUND
361     library = getLibrary( "libBuildGUI.so" );
362   }
363   else if( id == 5011 ||  // MENU BOOLEAN - FUSE
364            id == 5012 ||  // MENU BOOLEAN - COMMON
365            id == 5013 ||  // MENU BOOLEAN - CUT
366            id == 5014 ) { // MENU BOOLEAN - SECTION
367     library = getLibrary( "libBooleanGUI.so" );
368   }
369   else if( id == 5021 ||  // MENU TRANSFORMATION - TRANSLATION
370            id == 5022 ||  // MENU TRANSFORMATION - ROTATION
371            id == 5023 ||  // MENU TRANSFORMATION - LOCATION
372            id == 5024 ||  // MENU TRANSFORMATION - MIRROR
373            id == 5025 ||  // MENU TRANSFORMATION - SCALE
374            id == 5026 ||  // MENU TRANSFORMATION - OFFSET
375            id == 5027 ||  // MENU TRANSFORMATION - MULTI-TRANSLATION
376            id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
377     library = getLibrary( "libTransformationGUI.so" );
378   }
379   else if( id == 503 ||   // MENU OPERATION - PARTITION
380            id == 504 ||   // MENU OPERATION - ARCHIMEDE
381            id == 505 ||   // MENU OPERATION - FILLET
382            id == 506 ||   // MENU OPERATION - CHAMFER  
383            id == 507 ) {  // MENU OPERATION - CLIPPING RANGE
384     library = getLibrary( "libOperationGUI.so" );
385   }
386   else if( id == 601 ||   // MENU REPAIR - SEWING
387            id == 603 ||   // MENU REPAIR - SUPPRESS FACES
388            id == 604 ||   // MENU REPAIR - SUPPRESS HOLE
389            id == 605 ||   // MENU REPAIR - SHAPE PROCESSING
390            id == 606 ||   // MENU REPAIR - CLOSE CONTOUR
391            id == 607 ||   // MENU REPAIR - REMOVE INTERNAL WIRES
392            id == 608 ||   // MENU REPAIR - ADD POINT ON EDGE
393            id == 609 ||   // MENU REPAIR - FREE BOUNDARIES
394            id == 610 ||   // MENU REPAIR - FREE FACES
395            id == 602 ) {  // MENU REPAIR - GLUE FACES
396     library = getLibrary( "libRepairGUI.so" );
397   }
398   else if( id == 701   ||  // MENU MEASURE - PROPERTIES
399            id == 702   ||  // MENU MEASURE - CDG
400            id == 703   ||  // MENU MEASURE - INERTIA
401            id == 7041  ||  // MENU MEASURE - BOUNDING BOX
402            id == 7042  ||  // MENU MEASURE - MIN DISTANCE
403            id == 705   ||  // MENU MEASURE - TOLERANCE
404            id == 706   ||  // MENU MEASURE - WHATIS
405            id == 707   ||  // MENU MEASURE - CHECK
406            id == 7072  ||  // MENU MEASURE - CHECK COMPOUND OF BLOCKS
407            id == 708 ) {  // MENU MEASURE - POINT COORDINATES
408     library = getLibrary( "libMeasureGUI.so" );
409   }
410   else if( id == 800  ||  // MENU GROUP - CREATE
411            id == 8001 ||  // POPUP MENU - CREATE GROUP
412            id == 801 ) {  // MENU GROUP - EDIT
413     library = getLibrary( "libGroupGUI.so" );
414   }
415   else if( id == 9999  ||  // MENU BLOCKS - HEXAHEDRAL SOLID
416            id == 9998  ||  // MENU BLOCKS - MULTI-TRANSFORMATION
417            id == 9997  ||  // MENU BLOCKS - QUADRANGLE FACE
418            id == 99991 ||  // MENU BLOCKS - PROPAGATE
419            id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
420     library = getLibrary( "libBlocksGUI.so" );
421   }
422
423   // call method of corresponding GUI library
424   if ( library ) 
425     library->OnGUIEvent( id, desk );
426   else 
427     SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
428 }
429
430
431 //=================================================================================
432 // function : GeometryGUI::OnKeyPress()
433 // purpose  : Called when any key is pressed by user [static]
434 //=================================================================================
435 bool GeometryGUI::OnKeyPress( QKeyEvent* pe, SUIT_ViewWindow* win )
436 {
437   GUIMap::Iterator it;
438   bool bOk = true;
439   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
440     bOk = bOk && it.data()->OnKeyPress( pe, application()->desktop(), win );
441   return bOk;
442 }
443
444
445 //=================================================================================
446 // function : GeometryGUI::OnMouseMove()
447 // purpose  : Manages mouse move events [static]
448 //=================================================================================
449 bool GeometryGUI::OnMouseMove( QMouseEvent* pe, SUIT_ViewWindow* win )
450 {  
451   GUIMap::Iterator it;
452   bool bOk = true;
453   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
454     bOk = bOk && it.data()->OnMouseMove( pe, application()->desktop(), win );
455   return bOk;
456 }
457
458
459 //=================================================================================
460 // function : GeometryGUI::0nMousePress()
461 // purpose  : Manage mouse press events [static]
462 //=================================================================================
463 bool GeometryGUI::OnMousePress( QMouseEvent* pe, SUIT_ViewWindow* win )
464 {
465   GUIMap::Iterator it;
466   // OnMousePress() should return false if this event should be processed further
467   // (see OCCViewer_Viewer3d::onMousePress() for explanation)
468   bool processed = false;
469   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
470     processed = processed || it.data()->OnMousePress( pe, application()->desktop(), win );
471   return processed;
472 }
473
474 /*
475 static void UpdateVtkSelection()
476 {
477   QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
478   SUIT_ViewWindow* win = 0;
479   for ( win = winList.first(); win; win = winList.next() ) {
480     if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
481       VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
482       if ( vw ) {
483         VTKViewer_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
484         anInteractor->SetSelectionProp();
485         anInteractor->SetSelectionTolerance();
486         SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
487         if (aStyle) {
488           aStyle->setPreselectionProp();
489         }
490       }
491     }
492   }
493 }
494
495 //=================================================================================
496 // function : GeometryGUI::SetSettings()
497 // purpose  : Called when GEOM module is activated [static]
498 //=================================================================================
499 bool GeometryGUI::SetSettings()
500 {
501   QMenuBar*     Mb = parent->getMainMenuBar();
502   SUIT_Study*   ActiveStudy = application()->activeStudy();
503     
504 // Wireframe or Shading
505   int DisplayMode = 0;
506   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
507   bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
508   bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
509   if ( ViewOCC ) {
510     OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
511     if ( vm ) {
512       Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
513       DisplayMode = ic->DisplayMode();
514     }
515   }
516   else if ( ViewVTK ) {
517     VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
518     if ( vw ) {
519       VTKViewer_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
520       DisplayMode = myRenderInter->GetDisplayMode();
521     }
522   }
523
524   if( DisplayMode == 1 )
525     getApp()->
526     Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
527   else
528     Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
529
530
531   // Add in Study  - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
532   QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
533   int Settings_AddInStudy;
534   //  if(!AddInStudy.isEmpty())
535   //    Settings_AddInStudy = AddInStudy.toInt();
536   //  else
537   
538   Settings_AddInStudy = 1;
539   Mb->setItemChecked(411, Settings_AddInStudy);
540
541   // step value 
542   QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
543   if(S.isEmpty())
544     QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
545
546   // isos 
547   int count = ActiveStudy->getStudyFramesCount();
548   for(int i = 0; i < count; i++) {
549     if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
550       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
551       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
552
553       QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
554       QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
555       if(!IsoU.isEmpty())
556         ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
557       if(!IsoV.isEmpty())
558         ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
559     }
560   }
561
562   setActionsEnabled();
563
564   // PAL5356: update VTK selection
565   ::UpdateVtkSelection();
566   bool bOk = true;
567   GUIMap::Iterator it;
568   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
569     bOk = bOk && it.data()->SetSettings( parent );
570     
571   // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)        
572   if (getenv( "GEOM_CLIPPING" ) == NULL)
573     {
574       QMenuItem* mi = Mb->findItem(50);
575       if (mi && mi->popup())
576       mi->popup()->removeItem(507);     
577     } 
578     
579   return bOk;
580 }
581 */
582
583 //=======================================================================
584 // function : createGeomAction
585 // purpose  : 
586 //=======================================================================
587 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
588 {
589   QIconSet icon;
590   QWidget* parent = application()->desktop();
591   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
592   QPixmap pix;
593   if ( icon_id.length() ) 
594     pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
595   else
596     pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ) );
597   if ( !pix.isNull() )
598     icon = QIconSet( pix );
599
600   QString tooltip    = tr( QString( "TOP_" )+po_id ),
601           menu       = tr( QString( "MEN_" )+po_id ),
602           status_bar = tr( QString( "STB_" )+po_id );
603
604   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
605 }
606
607
608
609 //=======================================================================
610 // function : GeometryGUI::Deactivate()
611 // purpose  : Called when GEOM module is deactivated [ static ]
612 //=======================================================================
613 void GeometryGUI::initialize( CAM_Application* app )
614 {
615   SalomeApp_Module::initialize( app );
616
617   // ----- create actions --------------
618
619   createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
620   createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
621
622   createGeomAction( 33, "DELETE" );
623
624   createGeomAction( 4011, "POINT" );
625   createGeomAction( 4012, "LINE" );
626   createGeomAction( 4013, "CIRCLE" );
627   createGeomAction( 4014, "ELLIPSE" );
628   createGeomAction( 4015, "ARC" );
629   createGeomAction( 4019, "CURVE" );
630   createGeomAction( 4016, "VECTOR" );
631   createGeomAction( 4017, "PLANE" );
632   createGeomAction( 4018, "WORK_PLANE" );
633   createGeomAction( 4020, "LOCAL_CS" );
634
635   createGeomAction( 4021, "BOX" );
636   createGeomAction( 4022, "CYLINDER" );
637   createGeomAction( 4023, "SPHERE" );
638   createGeomAction( 4024, "TORUS" );
639   createGeomAction( 4025, "CONE" );
640
641   createGeomAction( 4031, "EXTRUSION" );
642   createGeomAction( 4032, "REVOLUTION" );
643   createGeomAction( 4033, "FILLING" );
644   createGeomAction( 4034, "PIPE" );
645
646   createGeomAction( 800, "GROUP_CREATE" );
647   createGeomAction( 801, "GROUP_EDIT" );
648
649   createGeomAction( 9997, "Q_FACE" );
650   createGeomAction( 9999, "HEX_SOLID" );
651
652   createGeomAction( 404, "SKETCH" );
653   createGeomAction( 407, "EXPLODE" );
654
655   createGeomAction( 4081, "EDGE" );
656   createGeomAction( 4082, "WIRE" );
657   createGeomAction( 4083, "FACE" );
658   createGeomAction( 4084, "SHELL" );
659   createGeomAction( 4085, "SOLID" );
660   createGeomAction( 4086, "COMPOUND" );
661
662   createGeomAction( 5011, "FUSE" );
663   createGeomAction( 5012, "COMMON" );
664   createGeomAction( 5013, "CUT" );
665   createGeomAction( 50114, "SECTION" );
666
667   createGeomAction( 5021, "TRANSLATION" );
668   createGeomAction( 5022, "ROTATION" );
669   createGeomAction( 5023, "MODIFY_LOCATION" );
670   createGeomAction( 5024, "MIRROR" );
671   createGeomAction( 5025, "SCALE" );
672   createGeomAction( 5026, "OFFSET" );
673   createGeomAction( 5027, "MUL_TRANSLATION" );
674   createGeomAction( 5028, "MUL_ROTATION" );
675
676   createGeomAction( 503, "PARTITION" );
677   createGeomAction( 504, "ARCHIMEDE" );
678   createGeomAction( 505, "FILLET" );
679   createGeomAction( 506, "CHAMFER" );
680   createGeomAction( 507, "CLIPPING" );
681
682   createGeomAction( 9998, "MUL_TRANSFORM" );
683   createGeomAction( 9995, "EXPLODE_BLOCKS" );
684   createGeomAction( 99991, "PROPAGATE" );
685
686   createGeomAction( 601, "SEWING" );
687   createGeomAction( 602, "GLUE_FACES" );
688   createGeomAction( 603, "SUPPRESS_FACES" );
689   createGeomAction( 604, "SUPPERSS_HOLES" );
690   createGeomAction( 605, "SHAPE_PROCESS" );
691   createGeomAction( 606, "CLOSE_CONTOUR" );
692   createGeomAction( 607, "SUPPRESS_INT_WIRES" );
693   createGeomAction( 608, "POINT_ON_EDGE" );
694   createGeomAction( 609, "CHECK_FREE_BNDS" );
695   createGeomAction( 610, "CHECK_FREE_FACES" );
696   
697   createGeomAction( 708, "POINT_COORDS" );
698   createGeomAction( 701, "BASIC_PROPS" );
699   createGeomAction( 702, "MASS_CENTER" );
700   createGeomAction( 703, "INERTIA" );
701   createGeomAction( 7041, "BND_BOX" );
702   createGeomAction( 7042, "MIN_DIST" );
703
704   createGeomAction( 705, "TOLERANCE" );
705   createGeomAction( 706, "WHAT_IS" );
706   createGeomAction( 707, "CHECK" );
707   createGeomAction( 7072, "CHECK_COMPOUND" );
708
709   createGeomAction( 5103, "CHECK_GEOMETRY" );
710   createGeomAction( 5104, "LOAD_SCRIPT" );
711
712   createGeomAction( 412, "SHADING_COLOR" );
713   createGeomAction( 413, "ISOS" );
714   createGeomAction( 414, "STEP_VALUE" );
715
716   createGeomAction( 211, "SHADING" );
717   createGeomAction( 212, "DISPLAY_ALL" );
718   createGeomAction( 214, "ERASE_ALL" );
719   createGeomAction( 216, "DISPLAY" );
720   createGeomAction( 213, "DISPLAY_ONLY" );
721   createGeomAction( 215, "ERASE" );
722
723   createGeomAction( 901, "POP_RENAME" );
724   createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
725   createGeomAction( 80312, "POP_SHADING", "", 0, true );
726   createGeomAction( 8032, "POP_COLOR" );
727   createGeomAction( 8033, "POP_TRANSPARENCY" );
728   createGeomAction( 8034, "POP_ISOS" );
729   createGeomAction( 8001, "POP_CREATE_GROUP" );
730
731   // make wireframe-shading items to be exclusive (only one at a time is selected)
732   //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
733   //dispModeGr->add( action( 80311 ) );
734   //dispModeGr->add( action( 80312 ) );
735   // ---- create menu --------------------------
736
737   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
738   createMenu( separator(), fileId, 10 );
739   createMenu( 111, fileId, 10 );
740   createMenu( 121, fileId, 10 );
741   createMenu( separator(), fileId, -1 );
742
743   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
744   createMenu( 33, editId, -1 );
745
746   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
747
748   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
749   createMenu( 4011, basicId, -1 );
750   createMenu( 4012, basicId, -1 );
751   createMenu( 4013, basicId, -1 );
752   createMenu( 4014, basicId, -1 );
753   createMenu( 4015, basicId, -1 );
754   createMenu( 4019, basicId, -1 );
755   createMenu( separator(), basicId, -1 );
756   createMenu( 4016, basicId, -1 );
757   createMenu( 4017, basicId, -1 );
758   createMenu( 4018, basicId, -1 );
759   createMenu( 4020, basicId, -1 );
760
761   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
762   createMenu( 4021, primId, -1 );  
763   createMenu( 4022, primId, -1 );  
764   createMenu( 4023, primId, -1 );  
765   createMenu( 4024, primId, -1 );  
766   createMenu( 4025, primId, -1 );  
767
768   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
769   createMenu( 4031, genId, -1 );  
770   createMenu( 4032, genId, -1 );  
771   createMenu( 4033, genId, -1 );  
772   createMenu( 4034, genId, -1 );  
773   createMenu( separator(), newEntId, -1 );
774
775   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
776   createMenu( 800, groupId, -1 );  
777   createMenu( 801, groupId, -1 );  
778   createMenu( separator(), newEntId, -1 );
779
780   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
781   createMenu( 9997, blocksId, -1 );  
782   createMenu( 9999, blocksId, -1 );  
783
784   createMenu( separator(), newEntId, -1 );
785   createMenu( 404, newEntId, -1 );  
786   createMenu( separator(), newEntId, -1 );
787   createMenu( 407, newEntId, -1 );  
788
789   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
790   createMenu( 4081, buildId, -1 );  
791   createMenu( 4082, buildId, -1 );  
792   createMenu( 4083, buildId, -1 );  
793   createMenu( 4084, buildId, -1 );  
794   createMenu( 4085, buildId, -1 );  
795   createMenu( 4086, buildId, -1 );  
796
797   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
798
799   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
800   createMenu( 5011, boolId, -1 );  
801   createMenu( 5012, boolId, -1 );  
802   createMenu( 5013, boolId, -1 );  
803   createMenu( 5014, boolId, -1 );  
804
805   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
806   createMenu( 5021, transId, -1 );  
807   createMenu( 5022, transId, -1 );  
808   createMenu( 5023, transId, -1 );  
809   createMenu( 5024, transId, -1 );  
810   createMenu( 5025, transId, -1 );  
811   createMenu( 5026, transId, -1 );  
812   createMenu( separator(), transId, -1 );
813   createMenu( 5027, transId, -1 );  
814   createMenu( 5028, transId, -1 );  
815
816   createMenu( 503, operId, -1 );  
817   createMenu( 504, operId, -1 );  
818   createMenu( separator(), operId, -1 );
819   createMenu( 505, transId, -1 );  
820   createMenu( 506, transId, -1 );  
821   createMenu( 507, transId, -1 );  
822
823   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
824   createMenu( 9998, blockId, -1 );  
825   createMenu( 9995, blockId, -1 );  
826   createMenu( 99991, blockId, -1 );  
827
828   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
829   createMenu( 605, repairId, -1 );  
830   createMenu( 603, repairId, -1 );  
831   createMenu( 606, repairId, -1 );  
832   createMenu( 607, repairId, -1 );  
833   createMenu( 604, repairId, -1 );  
834   createMenu( 601, repairId, -1 );  
835   createMenu( 602, repairId, -1 );  
836   createMenu( 608, repairId, -1 );  
837   createMenu( 609, repairId, -1 );  
838   createMenu( 610, repairId, -1 );  
839
840   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
841   createMenu( 708, measurId, -1 );  
842   createMenu( 701, measurId, -1 );  
843   createMenu( separator(), measurId, -1 );
844   createMenu( 702, measurId, -1 );  
845   createMenu( 703, measurId, -1 );  
846   createMenu( separator(), measurId, -1 );
847
848   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
849   createMenu( 7041, dimId, -1 );  
850   createMenu( 7042, dimId, -1 );
851   createMenu( separator(), measurId, -1 );
852   
853   createMenu( 705, measurId, -1 );  
854   createMenu( separator(), measurId, -1 );
855   createMenu( 706, measurId, -1 );  
856   createMenu( 707, measurId, -1 );  
857   createMenu( 7072, measurId, -1 );  
858
859   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 10 );
860   createMenu( separator(), toolsId, -1 );
861   createMenu( 5103, toolsId, -1 );  
862   createMenu( 5104, toolsId, -1 );  
863
864   int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 10 );
865   createMenu( separator(), prefId, -1 );
866
867   int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
868   createMenu( 412, geomId, -1 );  
869   createMenu( 413, geomId, -1 );  
870   createMenu( 414, geomId, -1 );  
871   createMenu( separator(), prefId, -1 );
872
873   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
874   createMenu( separator(), viewId, -1 );
875
876   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
877   createMenu( 211, dispmodeId, -1 );  
878   
879   createMenu( separator(), viewId, -1 );
880   createMenu( 212, viewId, -1 );  
881   createMenu( 214, viewId, -1 );  
882   createMenu( separator(), viewId, -1 );
883   createMenu( 216, viewId, -1 );  
884   createMenu( 213, viewId, -1 );  
885   createMenu( 215, viewId, -1 );
886
887   // ---- create toolbars --------------------------
888
889   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
890   createTool( 4011, basicTbId );
891   createTool( 4012, basicTbId );
892   createTool( 4013, basicTbId );
893   createTool( 4014, basicTbId );
894   createTool( 4015, basicTbId );
895   createTool( 4019, basicTbId );
896   createTool( 4016, basicTbId );
897   createTool( 4017, basicTbId );
898   createTool( 4018, basicTbId );
899   createTool( 4020, basicTbId );
900
901   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
902   createTool( 4021, primTbId );  
903   createTool( 4022, primTbId );  
904   createTool( 4023, primTbId );  
905   createTool( 4024, primTbId );  
906   createTool( 4025, primTbId );  
907
908   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
909   createTool( 5011, boolTbId );  
910   createTool( 5012, boolTbId );  
911   createTool( 5013, boolTbId );  
912   createTool( 5014, boolTbId );  
913
914   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
915   createTool( 4031, genTbId );  
916   createTool( 4032, genTbId );  
917   createTool( 4033, genTbId );  
918   createTool( 4034, genTbId );  
919
920   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
921   createTool( 5021, transTbId );  
922   createTool( 5022, transTbId );  
923   createTool( 5023, transTbId );  
924   createTool( 5024, transTbId );  
925   createTool( 5025, transTbId );  
926   createTool( 5026, transTbId );  
927   createTool( separator(), transTbId );
928   createTool( 5027, transTbId );  
929   createTool( 5028, transTbId );
930
931   QtxPopupMgr* mgr = popupMgr();
932   mgr->insert( action(  901 ), -1, -1 ); // rename
933   mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
934   mgr->insert( action(  8001 ), -1, -1 ); // create group
935   mgr->setRule( action( 8001 ), "$client in {'ObjectBrowser'} and $type in {'Shape'} and selcount=1 and isOCC", true );
936   mgr->insert( action(  801 ), -1, -1 ); // edit group
937   mgr->setRule( action( 801 ), "$client in {'ObjectBrowser'} and $type in {'Group'} and selcount=1 and isOCC", true );
938   mgr->insert( separator(), -1, -1 );        // -----------
939   mgr->insert( action(  216 ), -1, -1 ); // display
940   mgr->setRule( action( 216 ), "$client in {'ObjectBrowser'} and selcount>0 and (($type in {'Shape' 'Group'} and ($isVisible in {false})) or $type in {'Component'})", true );
941   mgr->insert( action(  215 ), -1, -1 ); // erase
942   mgr->setRule( action( 215 ), "$client in {'ObjectBrowser'} and selcount>0 and (($type in {'Shape' 'Group'} and $isVisible in {true}) or ($type in {'Component'} and selcount=1))", true );
943   mgr->insert( action(  213 ), -1, -1 ); // display only
944   mgr->setRule( action( 213 ), "$client in {'ObjectBrowser'} and selcount>0 and ($type in {'Shape' 'Group'} or ($type in {'Component'} and selcount=1))", true );
945   mgr->insert( separator(), -1, -1 );
946   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
947   mgr->insert( action(  80311 ), dispmodeId, -1 ); // wireframe
948   mgr->setRule( action( 80311 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
949   mgr->setRule( action( 80311 ), "$displaymode in {'Wireframe'}", false );
950   mgr->insert( action(  80312 ), dispmodeId, -1 ); // shading
951   mgr->setRule( action( 80312 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
952   mgr->setRule( action( 80312 ), "$displaymode in {'Shading'}", false );
953   mgr->insert( separator(), -1, -1 );
954   mgr->insert( action(  8032 ), -1, -1 ); // color
955   mgr->setRule( action( 8032 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
956   mgr->insert( action(  8033 ), -1, -1 ); // transparency
957   mgr->setRule( action( 8033 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
958   mgr->insert( action(  8034 ), -1, -1 ); // isos
959   mgr->setRule( action( 8034 ), "$client in {'OCCViewer'} and selcount>0", true );
960   mgr->insert( separator(), -1, -1 );        // -----------
961 }
962
963 //=======================================================================
964 // function : GeometryGUI::Deactivate()
965 // purpose  : Called when GEOM module is deactivated [ static ]
966 //=======================================================================
967 void GeometryGUI::activateModule( SUIT_Study* study )
968 {
969   SalomeApp_Module::activateModule( study );
970
971   setMenuShown( true );
972   setToolShown( true );
973
974   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), 
975           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
976   connect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
977            this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) ); 
978
979   GUIMap::Iterator it;
980   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
981     it.data()->activate( application()->desktop() );
982
983   SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
984   SUIT_ViewManager* vm;
985   ViewManagerList OCCViewManagers, VTKViewManagers;
986   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
987   for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
988     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
989   application()->viewManagers( VTKViewer_Viewer::Type(), VTKViewManagers );
990   for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
991     myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
992
993   // SetSettings() ?????????????
994 }
995
996
997 //=======================================================================
998 // function : GeometryGUI::Deactivate()
999 // purpose  : Called when GEOM module is deactivated [ static ]
1000 //=======================================================================
1001 void GeometryGUI::deactivateModule( SUIT_Study* study )
1002 {
1003   setMenuShown( false );
1004   setToolShown( false );
1005
1006   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), 
1007              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1008   disconnect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1009              this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) ); 
1010
1011   EmitSignalCloseAllDialogs();
1012
1013   GUIMap::Iterator it;
1014   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1015     it.data()->deactivate();  
1016
1017   myOCCSelectors.clear();
1018   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1019
1020   myVTKSelectors.clear();
1021
1022   SalomeApp_Module::deactivateModule( study );
1023 }
1024
1025 //=================================================================================
1026 // function : GeometryGUI::DefinePopup()
1027 // purpose  : Called from desktop to define popup menu [static]
1028 //=================================================================================
1029 /*
1030 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1031 {
1032   QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1033   SALOME_Selection* Sel  = SALOME_Selection::Selection(ActiveStudy->getSelection());
1034
1035   theObject  = "";
1036   theContext = "";
1037
1038   if ( theParent == "Viewer" ) {
1039     if ( Sel->IObjectCount() == 0 )
1040       theContext = "NothingSelected";
1041   }
1042
1043   if ( Sel->IObjectCount() == 1 ) {
1044     Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1045     if( IO->hasEntry() ) {
1046       SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1047       if ( !sobj->_is_nil() ) {
1048         SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1049         if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1050           // component is selected
1051           theObject = "Component";
1052         }
1053         else {
1054           GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1055           if ( !CORBA::is_nil( aGObj ) ) {
1056             switch( aGObj->GetType() ) {
1057             case GEOM_GROUP:
1058               theObject = "Group";
1059               break;
1060             default:
1061               theObject = "Shape";
1062               break;
1063             }
1064           }
1065         }
1066       }
1067     }
1068   }
1069 }
1070
1071 //=================================================================================
1072 // function : GeometryGUI::CustomPopup()
1073 // purpose  : Called from desktop to create popup menu [static]
1074 //=================================================================================
1075 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1076                               const QString& theParent, const QString& theObject)
1077 {
1078   GeometryGUI* geomGUI = GetGeomGUI();
1079
1080   // Deactivate any non modal dialog box to get the neutral point
1081   geomGUI->EmitSignalDeactivateDialog();
1082   QAD_Study* anActiveStudy    = parent->getActiveStudy();
1083   QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1084   QAD_ViewFrame* aViewFrame   = aStudyFrame->getRightFrame()->getViewFrame();
1085   SALOME_Selection* Sel       = SALOME_Selection::Selection(anActiveStudy->getSelection());
1086   QString parentComponent     = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1087   bool isOCCViewer            = aViewFrame->getTypeView() == VIEW_OCC;
1088   bool isVTKViewer            = aViewFrame->getTypeView() == VIEW_VTK;
1089   int aDisplayMode            = 0;
1090   QString objectName;
1091
1092   if ( aViewFrame->getTypeView() == VIEW_OCC )
1093     aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1094   else if ( aViewFrame->getTypeView() == VIEW_VTK )
1095     aDisplayMode = ((VTKViewer_ViewFrame*)aViewFrame)->getRWInteractor()->GetDisplayMode();
1096
1097   int nbSel = Sel->IObjectCount();
1098
1099   if( nbSel == 0 ) {
1100     ////// NOTHING SELECTED
1101     popup->clear();
1102   } 
1103   else if ( nbSel == 1 ) {
1104     ////// SINGLE OBJECT SELECTION
1105     if ( parentComponent != parent->getActiveComponent() )  {
1106       ////// selected object does not belong to GEOM module:
1107       // remove all commands except Display/Erase...
1108       while ( 1 ) {
1109         int id = popup->idAt( 0 );
1110         if ( id <= QAD_TopLabel_Popup_ID )
1111           popup->removeItemAt( 0 );
1112         else
1113           break;
1114       }
1115     }
1116     else {
1117       ////// selected object belong to the GEOM module
1118       // get interactive object
1119       Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1120       objectName = IObject->getName();
1121       // if object has entry get SObject
1122       SALOMEDS::SObject_var SO;
1123       if ( IObject->hasEntry() )
1124         SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1125
1126       if ( theObject == "Component" ) {
1127         ////// menu for component
1128         if ( !isOCCViewer && !isVTKViewer ) {
1129           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1130           popup->removeItem( QAD_Display_Popup_ID );
1131           popup->removeItem( QAD_Erase_Popup_ID );
1132         }
1133       }
1134       else {
1135         ////// not component (should be shape)
1136         if ( IObject->hasEntry() )  /////// VSR : TO BE REMOVED
1137           popup->removeItem( 804 ); // "Add in Study"
1138
1139         // Here could be analysis of the geom shape's type
1140         // ... //
1141
1142         SALOMEDS::GenericAttribute_var aTmpAttr;
1143         if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1144           popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1145
1146         if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1147           if ( theObject == "Shape" )
1148             popup->removeItem( 800 ); // Create Group
1149           else if ( theObject == "Group" )
1150             popup->removeItem( 801 ); // Edit Group
1151         }
1152
1153         if ( isOCCViewer || isVTKViewer ) {
1154           ////// current viewer is OCC or VTK
1155           SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1156           if ( aViewFrame->isVisible( IObject ) ) {
1157             ////// object is already displayed in the viewer
1158             popup->removeItem( QAD_Display_Popup_ID );
1159             if ( isOCCViewer ) {
1160               ////// OCC viewer only
1161               OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1162               if ( occPrs && !occPrs->IsNull() ) {
1163                 AIS_ListOfInteractive ioList;
1164                 occPrs->GetObjects( ioList );
1165                 QMenuItem* mi = popup->findItem( 803 );
1166                 if ( mi && mi->popup() ) {
1167                   if ( ioList.First()->DisplayMode() == 0 )
1168                     mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1169                   else if ( ioList.First()->DisplayMode() == 1 )
1170                     mi->popup()->setItemChecked( 80312, true ); // "Shading"
1171                   else if ( ioList.First()->DisplayMode() < 0 )
1172                     mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1173                 }
1174               }
1175             }
1176             else {
1177               ////// VTK viewer only
1178               popup->removeItem( 8034 ); // "Isos"
1179               VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( prs );
1180               if ( vtkPrs && !vtkPrs->IsNull() ) {
1181                 vtkActorCollection* actorList = vtkPrs->GetObjects();
1182                 actorList->InitTraversal();
1183                 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1184                 QMenuItem* mi = popup->findItem( 803 );
1185                 if ( ac && mi && mi->popup() ) {
1186                   if ( ac->getDisplayMode() == 0 )
1187                     mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1188                   else if ( ac->getDisplayMode() == 1 )
1189                     mi->popup()->setItemChecked( 80312, true ); // "Shading"
1190                   else
1191                     mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1192                 }
1193               }
1194             }
1195           }
1196           else {
1197             ////// object is not yet displayed in the viewer
1198             popup->removeItem( 803 );  // "Display Mode"
1199             popup->removeItem( 8032 ); // "Color"
1200             popup->removeItem( 8033 ); // "Transparency"
1201             popup->removeItem( 8034 ); // "Isos"
1202             popup->removeItem( QAD_Erase_Popup_ID );
1203           }
1204           delete prs;
1205         }
1206         else {
1207           ////// other viewer type (neither OCC nor VTK)
1208           popup->removeItem( 803 );  // "Display Mode"
1209           popup->removeItem( 8032 ); // "Color"
1210           popup->removeItem( 8033 ); // "Transparency"
1211           popup->removeItem( 8034 ); // "Isos"
1212           popup->removeItem( QAD_Display_Popup_ID );
1213           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1214           popup->removeItem( QAD_Erase_Popup_ID );
1215         }
1216       }
1217     }
1218   }
1219   else {
1220     ////// MULTIPLE SELECTION
1221     if ( parentComponent != parent->getActiveComponent() )  {
1222       ////// not GEOM module objects or objects belong to different modules
1223       // remove all commands except Display/Erase...
1224       while ( 1 ) {
1225         int id = popup->idAt( 0 );
1226         if ( id <= QAD_TopLabel_Popup_ID )
1227           popup->removeItemAt( 0 );
1228         else
1229           break;
1230       }
1231       if ( parentComponent.isNull() )  {
1232         ////// objects belong to different modules
1233         popup->removeItem(QAD_Display_Popup_ID);
1234         popup->removeItem(QAD_DisplayOnly_Popup_ID);
1235         popup->removeItem(QAD_Erase_Popup_ID);
1236       }
1237       else {
1238         objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1239       }
1240     }
1241     else {
1242       ////// all selected objects belong to GEOM module
1243       popup->removeItem( 901 ); // "Rename"
1244
1245       SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1246       bool isComponent  = false;
1247       bool needOpen     = false;
1248       bool needDisplay  = false;
1249       bool needErase    = false;
1250       int needToPublish = 0;
1251
1252       for( ;It.More();It.Next() ) {
1253         Handle(SALOME_InteractiveObject) anIObject = It.Value();
1254
1255         if ( aViewFrame->isVisible( anIObject ) )
1256           needErase   = true;
1257         else
1258           needDisplay = true;
1259
1260         if( anIObject->hasEntry() ) {
1261           needToPublish = -1; /////// VSR : TO BE REMOVED
1262           SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1263           SALOMEDS::GenericAttribute_var aTmpAttr;
1264           if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1265             needOpen = true;  /////// VSR : TO BE REMOVED
1266           if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1267             isComponent = true;
1268         }
1269         else {
1270           if ( needToPublish != -1 ) needToPublish = 1;
1271         }
1272       }
1273       if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1274         ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1275         popup->removeItem( 803 );  // "Display Mode"
1276         popup->removeItem( 8032 ); // "Color"
1277         popup->removeItem( 8033 ); // "Transparency"
1278         popup->removeItem( 8034 ); // "Isos"
1279         popup->removeItem( 804 );  // "Add in Study"
1280         popup->removeItem( QAD_DisplayOnly_Popup_ID );
1281         popup->removeItem( QAD_Display_Popup_ID );
1282         popup->removeItem( QAD_Erase_Popup_ID );
1283       }
1284       else {
1285         popup->removeItem( 9024 );   // "Open"
1286         if ( needToPublish <= 0 )
1287           popup->removeItem( 804 );  // "Add in Study"
1288
1289         if( isComponent ) {
1290           popup->removeItem( 803 );  // "Display Mode"
1291           popup->removeItem( 8032 ); // "Color"
1292           popup->removeItem( 8033 ); // "Transparency"
1293           popup->removeItem( 8034 ); // "Isos"
1294           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1295         }
1296
1297         if ( !needDisplay )
1298           popup->removeItem( QAD_Display_Popup_ID );
1299         if ( !needErase )
1300           popup->removeItem( QAD_Erase_Popup_ID );
1301         if ( !isOCCViewer )
1302           popup->removeItem( 8034 ); // "Isos"
1303       }
1304     }
1305   }
1306
1307   // check popup for unnecessary separators
1308   QAD_Tools::checkPopup( popup );
1309   // find popup menu's TopLabel item (with title)
1310   int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1311   if ( topItem >= 0 ) {
1312     // remove popup menu's title item
1313     popup->removeItem( QAD_TopLabel_Popup_ID );
1314     if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1315       // set bold font for popup menu's title
1316       QFont f = popup->font(); f.setBold( TRUE );
1317       popup->removeItem( QAD_TopLabel_Popup_ID );
1318       popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1319     }
1320   }
1321
1322   return false;
1323 }
1324
1325 */
1326
1327 //=======================================================================
1328 // function : GeometryGUI::BuildPresentation()
1329 // purpose  : 
1330 //=======================================================================
1331 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1332 {
1333   //GEOM_Displayer().Display( io, false, win );
1334 }
1335
1336 //=======================================================================
1337 // function : setCommandsEnabled()
1338 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1339 //=======================================================================
1340 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1341 {
1342   if ( !win )
1343     return;
1344
1345   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1346 //  const bool ViewVTK = ( win->getViewManager()->getType() == VTKViewer_Viewer::Type() );
1347
1348   // disable OCC selectors
1349   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1350   for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1351     sr->setEnabled(true);
1352   
1353   // disable non-OCC viewframe menu commands
1354 //  action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1355   action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1356   action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1357   action( 606 )->setEnabled( ViewOCC ); // CloseContour
1358   action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1359   action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1360 //  action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1361   action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1362
1363   action( 800 )->setEnabled( ViewOCC ); // Create Group
1364   action( 801 )->setEnabled( ViewOCC ); // Edit Group
1365
1366   action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1367 }
1368
1369 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1370 {
1371   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1372   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1373 }
1374
1375 void GeometryGUI::viewManagers( QStringList& lst ) const
1376 {
1377   lst.append( OCCViewer_Viewer::Type() );
1378 }
1379
1380 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1381 {
1382   if ( vm->getType() == OCCViewer_Viewer::Type() )
1383   {
1384     SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1385     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1386   }
1387   else if ( vm->getType() == VTKViewer_Viewer::Type() )
1388   {
1389     SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1390     myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
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     for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1400       if ( sr->viewer() == viewer )
1401       {
1402         myOCCSelectors.remove( sr );
1403         break;
1404       }
1405   }
1406   if ( vm->getType() == VTKViewer_Viewer::Type() )
1407   {
1408     for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1409       if ( sr->viewer() == viewer )
1410       {
1411         myVTKSelectors.remove( sr );
1412         break;
1413       }
1414   }
1415 }
1416
1417 QString GeometryGUI::engineIOR() const
1418 {
1419   if ( !CORBA::is_nil( GetGeomGen() ) )
1420     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1421   return QString( "" );
1422 }
1423
1424 SalomeApp_Selection* GeometryGUI::createSelection() const
1425 {
1426   return new GEOMGUI_Selection();
1427 }
1428
1429 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1430 {
1431   SalomeApp_Module::contextMenuPopup( client, menu, title );
1432   SALOME_ListIO lst;
1433   getApp()->selectionMgr()->selectedObjects( lst );
1434   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1435     Handle(SALOME_InteractiveObject) io = lst.First();
1436     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1437     _PTR(Study) study = appStudy->studyDS();
1438     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1439     if ( obj )
1440       title = QString( obj->GetName().c_str() );
1441   }
1442 }