Salome HOME
sources v1.2
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
1 using namespace std;
2 //  File      : GeometryGUI.cxx
3 //  Created   : 
4 //  Author    : Lucien PIGNOLONI
5 //  Project   : SALOME
6 //  Module    : GeometryGUI
7 //  Copyright : OPEN CASCADE
8 //  $Header$
9
10 #include "GeometryGUI.h"
11
12 // SALOME Includes
13 # include "Utils_ORB_INIT.hxx"
14 # include "Utils_SINGLETON.hxx"
15
16 #include "QAD.h"
17 #include "QAD_Tools.h"
18 #include "QAD_Config.h"
19 #include "QAD_Settings.h"
20 #include "QAD_RightFrame.h"
21 #include "QAD_MessageBox.h"
22 #include "QAD_Resource.h"
23 #include "QAD_FileDlg.h"
24
25 #include "OCCViewer_ViewPort.h"
26 #include "OCCViewer_ViewPort3d.h"
27 #include "OCCViewer_Viewer3d.h"
28
29 #include "VTKViewer_RenderWindowInteractor.h"
30 #include "VTKViewer_ViewFrame.h"
31
32 #include "GEOM_Actor.h"
33 #include "GEOM_Client.hxx"
34 #include "GEOM_AISShape.hxx"
35 #include "GEOM_AssemblyBuilder.h"
36 #include "GEOM_InteractiveObject.hxx"
37
38 #include "SALOME_NamingService.hxx"
39 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "SALOME_InteractiveObject.hxx"
41
42 #include "SALOMEGUI_ImportOperation.h"
43 #include "SALOMEGUI_QtCatchCorbaException.hxx"
44 #include "SALOMEGUI_NameDlg.h"            
45 #include "utilities.h"
46
47 // Open CASCADE Includes
48 #include <AIS_Shape.hxx>
49 #include <AIS_InteractiveContext.hxx>
50 #include <AIS_ListIteratorOfListOfInteractive.hxx>
51 #include <AIS_Drawer.hxx>
52 #include <AIS_Trihedron.hxx>
53 #include <Prs3d_Drawer.hxx>
54 #include <Prs3d_IsoAspect.hxx>
55 #include <Prs3d_ShadingAspect.hxx>
56
57 #include <BRep_Builder.hxx>
58 #include <BRepAdaptor_Surface.hxx>
59 #include <BRepAdaptor_Curve.hxx>
60 #include <BRep_Tool.hxx>
61 #include <BRepGProp.hxx>
62 #include <BRepExtrema_DistShapeShape.hxx>
63 #include <GProp_GProps.hxx>
64 #include <GProp_PrincipalProps.hxx>
65
66 #include <BRepAlgoAPI_Fuse.hxx>
67 #include <BRepAlgoAPI_Cut.hxx>
68 #include <BRepAlgoAPI_Section.hxx>
69 #include <BRepAlgoAPI_Common.hxx>
70 #include <BRepPrimAPI_MakeBox.hxx>
71 #include <BRepPrimAPI_MakeCylinder.hxx>
72 #include <BRepPrimAPI_MakePrism.hxx>
73 #include <BRepPrimAPI_MakeSphere.hxx>
74 #include <BRepPrimAPI_MakeRevol.hxx>
75 #include <BRepPrimAPI_MakeTorus.hxx>
76 #include <BRepPrimAPI_MakeCone.hxx>
77 #include <BRepBuilderAPI_MakeVertex.hxx>
78 #include <BRepBuilderAPI_MakeEdge.hxx>
79 #include <BRepBuilderAPI_MakeWire.hxx>
80 #include <BRepBuilderAPI_MakeFace.hxx>
81 #include <BRepBuilderAPI_Transform.hxx>
82
83 #include <BRepTools.hxx>
84 #include <BRepTools_WireExplorer.hxx>
85 #include <BRepCheck_Analyzer.hxx>
86
87 #include <Geom_Circle.hxx>
88 #include <Geom_Line.hxx>
89 #include <Geom_Plane.hxx>
90 #include <Geom_Surface.hxx>
91 #include <Geom_Axis2Placement.hxx>
92 #include <Geom_TrimmedCurve.hxx>
93
94 #include <GeomAPI_ProjectPointOnCurve.hxx>
95 #include <GC_MakeArcOfCircle.hxx>
96 #include <gp_Pnt.hxx>
97 #include <gp_Circ.hxx>
98 #include <gp_Pln.hxx>
99 #include <gp_Mat.hxx>
100
101 #include <TopTools_MapOfShape.hxx>
102 #include <TopTools_MapIteratorOfMapOfShape.hxx>
103 #include <TopTools_ListIteratorOfListOfShape.hxx>
104 #include <TopoDS_Iterator.hxx>
105
106 //VRV: OCC 4.0 migration
107 #include <IGESControl_Writer.hxx>
108 #include <IGESControl_Controller.hxx>
109 #include <STEPControl_Writer.hxx>
110 //#include <STEPControlStd_StepModelType.hxx>
111 //VRV: OCC 4.0 migration
112
113 #include <TopoDS.hxx>
114 #include <TopoDS_Wire.hxx>
115 #include <TopoDS_Shape.hxx>
116 #include <TopoDS_Compound.hxx>
117 #include <TopAbs.hxx>
118 #include <TopExp.hxx>
119 #include <TopExp_Explorer.hxx>
120
121 #include <Precision.hxx>
122 #include <ProjLib.hxx>
123 #include <ElSLib.hxx>
124
125 #include <IFSelect_ReturnStatus.hxx>
126 #include <Interface_Static.hxx>
127
128 // QT Includes
129 #define  INCLUDE_MENUITEM_DEF
130 #include <qapplication.h>
131 #include <qmenudata.h>
132 #include <qmenubar.h>
133 #include <qpopupmenu.h>
134 #include <qfont.h>
135 #include <qstring.h>
136 #include <qcheckbox.h>
137 #include <qcolordialog.h>
138 #include <qmessagebox.h>
139 #include <qspinbox.h>
140 #include <qlist.h>
141 #include <qwidget.h> 
142 #include <qevent.h> 
143 #include <qlineedit.h>
144 #include "GeometryGUI_aParameterDlg.h"
145
146 #include "GeometryGUI_PointDlg.h"         // Method POINT
147 #include "GeometryGUI_BoxDlg.h"           // Method BOX
148 #include "GeometryGUI_VectorDlg.h"        // Method VECTOR
149 #include "GeometryGUI_PlaneDlg.h"         // Method PLANE
150 #include "GeometryGUI_PrismDlg.h"         // Method PRISM
151 #include "GeometryGUI_FuseDlg.h"          // Method FUSE
152 #include "GeometryGUI_CommonDlg.h"        // Method COMMON
153 #include "GeometryGUI_CutDlg.h"           // Method CUT
154 #include "GeometryGUI_SectionDlg.h"       // Method SECTION
155
156 #include "GeometryGUI_LineDlg.h"          // Method LINE
157 #include "GeometryGUI_ScaleDlg.h"         // Method SCALE
158 #include "GeometryGUI_MirrorDlg.h"        // Method MIRROR
159 #include "GeometryGUI_SphereDlg.h"        // Method SPHERE
160 #include "GeometryGUI_CircleDlg.h"        // Method CIRCLE
161 #include "GeometryGUI_RevolDlg.h"         // Method REVOL
162 #include "GeometryGUI_RotationDlg.h"      // Method ROTATION
163 #include "GeometryGUI_TranslationDlg.h"   // Method TRANSLATION
164 #include "GeometryGUI_MultiTranslationDlg.h"   // Method MULTI TRANSLATION
165 #include "GeometryGUI_MultiRotationDlg.h" // Method MULTI ROTATION
166 #include "GeometryGUI_ArcDlg.h"           // Method ARC
167 #include "GeometryGUI_PipeDlg.h"          // Method PIPE
168 #include "GeometryGUI_CylinderDlg.h"      // Method CYLINDER
169 #include "GeometryGUI_ConeDlg.h"          // Method CONE
170 #include "GeometryGUI_TorusDlg.h"         // Method TORUS
171 #include "GeometryGUI_FillingDlg.h"       // Method FILLING
172 #include "GeometryGUI_SewingDlg.h"        // Method SEWING
173 #include "GeometryGUI_CompoundDlg.h"      // Method GEOM::COMPOUND
174 #include "GeometryGUI_EdgeDlg.h"          // Method GEOM::EDGE
175 #include "GeometryGUI_OrientationDlg.h"   // Method ORIENTATION
176 #include "GeometryGUI_PartitionDlg.h"     // Method PARTITION
177 #include "GeometryGUI_SubShapeDlg.h"      // Method EXPLODE
178 #include "GeometryGUI_WireDlg.h"          // Method GEOM::WIRE
179 #include "GeometryGUI_WorkingPlaneDlg.h"  // Method WORKING PLANE
180 #include "GeometryGUI_PropertiesDlg.h"    // Method PROPERTIES
181 #include "GeometryGUI_CenterMassDlg.h"    // Method CENTER MASS
182 #include "GeometryGUI_InertiaDlg.h"       // Method INERTIA
183 #include "GeometryGUI_FaceDlg.h"          // Method GEOM::FACE
184 #include "GeometryGUI_FilletDlg.h"        // Method FILLET
185 #include "GeometryGUI_ChamferDlg.h"       // Method CHAMFER
186 #include "GeometryGUI_FillingHoleDlg.h"   // Method FILLING HOLE
187 #include "GeometryGUI_SuppressFacesDlg.h" // Method SUPPRESS FACES
188 #include "GeometryGUI_CheckShape.h"       // Method CHECKSHAPE
189 #include "GeometryGUI_ArchimedeDlg.h"     // Method ARCHIMEDE
190 #include "GeometryGUI_TransparencyDlg.h"  // Method TRANSPARENCY adjustement
191 #include "GeometryGUI_NbIsosDlg.h"        // Method ISOS adjustement
192 #include "GeometryGUI_BndBoxDlg.h"        // Method BNDBOX
193 #include "GeometryGUI_MaxToleranceDlg.h"  // Method MAXTOLERANCE
194 #include "GeometryGUI_WhatisDlg.h"        // Method WHATIS
195 #include "GeometryGUI_DistanceDlg.h"      // Method DISTANCE
196 #include "GeometryGUI_SuppressHoleDlg.h"  // Method SUPPRESS HOLE
197
198
199 static Handle(AIS_Shape) theConstructionShape = new AIS_Shape(TopoDS_Shape());
200 static Handle(GEOM_AISShape) theSelectedShape = new GEOM_AISShape(TopoDS_Shape(), "");
201
202 static AIS_ListOfInteractive ListDisplayedObject;
203
204 static bool Settings_AddInStudy = false;
205 static bool Settings_Copy = false;
206 static Standard_CString Fatherior = "";
207 static GEOM_Client ShapeReader;
208
209 /* The object itself created in the static method 'GetOrCreateGeometryGUI()' */
210 static GeometryGUI* GeomGUI = 0;
211
212
213
214 //=======================================================================
215 // class   : CustomItem
216 // purpose : Set Font to a text.
217 //=======================================================================
218 class CustomItem : public QCustomMenuItem
219 {
220 public:
221   CustomItem( const QString& s, const QFont& f )
222     : string( s ), font( f ){};
223   ~CustomItem(){}
224   
225   void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
226   {
227     p->setFont ( font );
228     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
229   }
230   
231   QSize sizeHint()
232   {
233     return QFontMetrics( font ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip,  string );
234   }
235 private:
236   QString string;
237   QFont font;
238 };
239
240
241
242
243 //=======================================================================
244 // function : GeometryGUI()
245 // purpose  : Constructor
246 //=======================================================================
247 GeometryGUI::GeometryGUI() :
248   QObject()
249 {
250 }
251
252 //=======================================================================
253 // function : ~GeometryGUI()
254 // purpose  : Destructor
255 //=======================================================================
256 GeometryGUI::~GeometryGUI()
257 {
258 }
259
260
261 //=======================================================================
262 // function : GetGeometryGUI() static
263 // purpose  : Returns current 'GeomGUI' a static pointer
264 //=======================================================================
265 GeometryGUI* GeometryGUI::GetGeometryGUI( )
266 {
267   return GeomGUI;
268 }
269
270
271 //=====================================================================================
272 // function : GetIndex()
273 // purpose  : Get the index of a sub shape in a main shape : index start at 1
274 //=====================================================================================
275 int  GeometryGUI::GetIndex(const TopoDS_Shape& subshape, 
276       const TopoDS_Shape& shape, 
277       int /*ShapeType*/) 
278
279   if( shape.IsNull() || subshape.IsNull() ) 
280     return -1 ; 
281   
282   int index = 1; 
283   if (subshape.ShapeType() == TopAbs_COMPOUND) 
284   { 
285     TopoDS_Iterator it; 
286     TopTools_ListOfShape CL; 
287     CL.Append( shape ); 
288     TopTools_ListIteratorOfListOfShape itC; 
289     for (itC.Initialize( CL ); itC.More(); itC.Next()) 
290       { 
291         for (it.Initialize( itC.Value() );  it.More(); it.Next()) 
292           { 
293             if ( it.Value().ShapeType() == TopAbs_COMPOUND) 
294               {
295                 if (it.Value().IsSame(subshape)) 
296                   return index; 
297                 else 
298                   index++; 
299                 CL.Append( it.Value() ); 
300               }
301           } 
302       } 
303   } 
304   else 
305     { 
306       TopExp_Explorer Exp ( shape,  subshape.ShapeType() ); 
307       TopTools_MapOfShape M; 
308       while ( Exp.More() ) 
309         {
310           if ( M.Add(Exp.Current()) ) 
311             { 
312               if ( Exp.Current().IsSame(subshape) ) 
313                 return index; 
314               index++; 
315             } 
316           Exp.Next(); 
317         } 
318     } 
319   return -1; 
320
321
322 //=======================================================================
323 // function : GetOrCreateGeometryGUI()
324 // purpose  : Gets or create an object 'GeometryGUI' with initialisations
325 //          : Returns 'GeomGUI' as a pointer
326 //=======================================================================
327 GeometryGUI* GeometryGUI::GetOrCreateGeometryGUI( QAD_Desktop* desktop )
328 {
329   if( GeomGUI == 0 ) {
330     GeomGUI = new GeometryGUI;
331     GeomGUI->myActiveDialogBox = 0 ;
332     GeomGUI->mySimulationShape = new AIS_Shape(TopoDS_Shape());
333     GeomGUI->myState = -1 ;
334     GeomGUI->myDesktop = desktop ; 
335     GeomGUI->myActiveStudy = desktop->getActiveStudy();
336     GeomGUI->mySimulationActor = vtkActorCollection::New() ;
337
338     GeomGUI->myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
339
340     Engines::Component_var comp = desktop->getEngine("FactoryServer", "Geometry");
341     GeomGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp);
342     
343     /* GetCurrentStudy */
344     int studyId = GeomGUI->myActiveStudy->getStudyId();
345     GeomGUI->myComponentGeom->GetCurrentStudy(studyId);
346
347     GeomGUI->myNbGeom = GeomGUI->myComponentGeom->NbLabels();
348   } else {
349     /* study may have changed */
350     GeomGUI->myActiveStudy = desktop->getActiveStudy();
351   }
352   return GeomGUI;
353 }
354
355
356 //=================================================================================
357 // function : VertexToPoint()
358 // purpose  : If S can be converted in a gp_Pnt returns true and the result is P
359 //=================================================================================
360 bool GeometryGUI::VertexToPoint( const TopoDS_Shape& S, gp_Pnt& P )
361 {
362   if( S.IsNull() || S.ShapeType() != TopAbs_VERTEX )
363     return false ;
364   P = BRep_Tool::Pnt(TopoDS::Vertex( S ));
365   return true ;
366 }
367
368
369 //=================================================================================
370 // function : LinearEdgeExtremities()
371 // purpose  : If S can be converted in a linear edge and if initial an final points
372 //          : distance is sufficient, returns true else returns false.
373 //          : Resulting points are respectively P1 and P2
374 //=================================================================================
375 bool GeometryGUI::LinearEdgeExtremities( const TopoDS_Shape& S,  gp_Pnt& P1, gp_Pnt& P2 )
376 {
377   if( S.IsNull() || S.ShapeType() != TopAbs_EDGE )
378     return false ;
379   BRepAdaptor_Curve curv(TopoDS::Edge(S));
380   if (curv.GetType() != GeomAbs_Line)
381     return false ;
382
383   curv.D0( curv.FirstParameter(), P1 );
384   curv.D0( curv.LastParameter(), P2 );
385
386   if( P1.Distance(P2) <= Precision::Confusion() )
387     return false ;
388   
389   return true ;
390 }
391
392 //=================================================================================
393 // function : GetBipointDxDyDz()
394 // purpose  : 
395 //=================================================================================
396 void GeometryGUI::GetBipointDxDyDz( gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz )
397 {
398   dx = P2.X() - P1.X() ;
399   dy = P2.Y() - P1.Y() ;
400   dz = P2.Z() - P1.Z() ;
401   return ;
402 }
403
404 //=======================================================================
405 // function : GetTopoFromSelection()
406 // purpose  : Define tds from a single selection and retuen true
407 //=======================================================================
408 bool GeometryGUI::GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds) 
409 {
410   if(Sel->IObjectCount() != 1)
411     return false ;
412   
413   Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
414   /* case SObject */
415   if ( IO->hasEntry() ) {
416     SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
417     SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
418     SALOMEDS::GenericAttribute_var anAttr;
419     SALOMEDS::AttributeIOR_var     anIOR;
420     if ( !obj->_is_nil() ) {
421        if (obj->FindAttribute(anAttr, "AttributeIOR")) {
422          anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
423          tds = this->GetShapeFromIOR(anIOR->Value());
424          if(tds.IsNull() )
425            return false ;
426          else
427            return true ;
428        }
429     }
430   }
431
432   if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
433     Standard_CString ior = "";
434     Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
435     ior = GIObject->getIOR();
436     tds = this->GetShapeFromIOR(ior);
437     if(tds.IsNull() )
438       return false ;
439     else
440       return true ;
441   }
442   
443   return false;
444 }
445
446
447
448 //=====================================================================================
449 // function : PrepareSubShapeSelection()
450 // purpose  : ( localContextId of the method is opened and defined here)
451 //=====================================================================================
452 bool GeometryGUI::PrepareSubShapeSelection(const int SubShapeType, Standard_Integer& returnLocalContextId)
453 {
454   //* Test the type of viewer */
455   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
456     return false;
457   
458   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
459   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
460   
461   /* local context opening */
462   SetDisplayedObjectList() ;
463   OnDisplayOnly();
464
465   returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False) ;
466   SALOME_Selection* Sel = SALOME_Selection::Selection( this->myActiveStudy->getSelection() );
467   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
468   for(;It.More();It.Next()) {
469     Handle(SALOME_InteractiveObject) IObject = It.Value();
470     Standard_Boolean found;
471     Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found);
472     if ( found && SubShapeType >= Shape->Shape().ShapeType()) {
473       ic->Load(Shape, (8 - SubShapeType), Standard_True);
474       ic->HilightWithColor(Shape, Quantity_NOC_RED);
475     }
476   }
477   myDesktop->putInfo (tr("GEOM_PRP_SELECT_SUBSHAPES"));
478   return true ;
479 }
480
481
482
483 //=====================================================================================
484 // function : PrepareSubShapeSelectionArgumentShape()
485 // purpose  : ( localContextId of the method is opened and defined here )
486 //=====================================================================================
487 bool GeometryGUI::PrepareSubShapeSelectionArgumentShape( const TopoDS_Shape& aShape,
488                                                          const int SubShapeType,
489                                                          Standard_Integer& returnLocalContextId )
490 {
491   //* Test the type of viewer */
492   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
493     return false;
494   
495   if( aShape.IsNull() )
496     return false ;
497   
498   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
499   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
500   
501   /* local context opening */
502   SetDisplayedObjectList() ;
503   OnDisplayOnly();
504   
505   returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False) ;
506   
507   Handle(GEOM_AISShape) Shape = new GEOM_AISShape(aShape, "") ;  
508   ic->Display(Shape, 0, (8 - SubShapeType));
509
510   //  Not Load(...) but Display(...)
511   //  ic->Load(Shape, (8 - SubShapeType), Standard_True);
512   ic->HilightWithColor(Shape, Quantity_NOC_RED);
513   
514   myDesktop->putInfo (tr("GEOM_PRP_SELECT_SUBSHAPES"));
515   return true ;
516 }
517
518
519
520 //=======================================================================
521 // function : GetNameOfSelectedIObjects()
522 // purpose  : Define the name geom++ or other name of mono or multi sel.
523 //=======================================================================
524 int GeometryGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel,
525                                             QString& aName )
526 {
527   int nbSel = Sel->IObjectCount() ;
528   if ( nbSel == 1 ) {
529     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
530     aName = IObject->getName();
531   } else {
532     aName = tr( "%1_objects" ).arg( nbSel );
533   }
534   return nbSel;
535 }
536
537
538 //=======================================================================
539 // function : ConvertIOinGEOMAISShape()
540 // purpose  :
541 //=======================================================================
542 Handle(GEOM_AISShape) GeometryGUI::ConvertIOinGEOMAISShape( const Handle(SALOME_InteractiveObject)& IO,
543                                                             Standard_Boolean& testResult,
544                                                             bool onlyInActiveView )
545 {
546   Handle(GEOM_AISShape) res;
547   int nbSf = myActiveStudy->getStudyFramesCount();
548   for ( int i = 0; i < nbSf; i++ ) {
549     QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
550     if ( sf->getTypeView() == VIEW_OCC ) {
551       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
552       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
553
554       AIS_ListOfInteractive List;
555       ic->DisplayedObjects(List);
556       AIS_ListOfInteractive List1;
557       ic->ObjectsInCollector(List1);
558       List.Append(List1);
559       
560       AIS_ListIteratorOfListOfInteractive ite(List);
561       while (ite.More()) {
562         if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
563           Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
564           if ( aSh->hasIO() ) {
565             Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
566             if ( GIO->isSame( IO ) ) {
567               if ( onlyInActiveView ) {
568                 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
569                   testResult = true;
570                   return aSh;
571                 }
572               } else {
573                 testResult = true;
574                 return aSh;
575               }
576             }
577           }
578         }
579         ite.Next();
580       }  
581     }
582   }
583   testResult = false;
584   return res;
585 }
586
587 //=======================================================================
588 // function : ConvertIORinGEOMAISShape()
589 // purpose  :
590 //=======================================================================
591 Handle(GEOM_AISShape) GeometryGUI::ConvertIORinGEOMAISShape( const char * IOR,
592                                                              Standard_Boolean& testResult,
593                                                              bool onlyInActiveView )
594 {
595 Handle(GEOM_AISShape) resultShape;
596 testResult = false;
597   int nbSf = myActiveStudy->getStudyFramesCount();
598   for ( int i = 0; i < nbSf; i++ ) 
599     {
600       QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
601       if ( sf->getTypeView() == VIEW_OCC ) 
602         {
603           OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
604           Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
605
606           AIS_ListOfInteractive List;
607           ic->DisplayedObjects(List);
608           AIS_ListOfInteractive List1;
609           ic->ObjectsInCollector(List1);
610           List.Append(List1);
611       
612           AIS_ListIteratorOfListOfInteractive ite(List);
613           while (ite.More()) 
614             {
615               if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) 
616                 {
617                   Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
618                   if (  aSh->hasIO() ) 
619                     {
620                       Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
621                       Standard_CString theIOR = GIO->getIOR();
622                       if ( strcmp( IOR, theIOR ) == 0 ) 
623                         {
624                           if ( onlyInActiveView ) 
625                             {
626                               if ( sf == myActiveStudy->getActiveStudyFrame() ) 
627                                 {
628                                   testResult = true;
629                                   resultShape = aSh;
630                                   return resultShape; 
631                                 }
632                             } 
633                           else 
634                             {
635                               testResult = true;
636                               resultShape = aSh;
637                               return resultShape; 
638                             }
639                         }
640                     }
641                 }
642               ite.Next();
643             }  
644         }
645     }
646 return  resultShape;
647 }
648 //=======================================================================
649 // function : ConvertIORinGEOMActor()
650 // purpose  :
651 //=======================================================================
652 GEOM_Actor* GeometryGUI::ConvertIORinGEOMActor( const char * IOR,
653                                                 Standard_Boolean& testResult,
654                                                 bool onlyInActiveView )
655 {
656   int nbSf = GeomGUI->myActiveStudy->getStudyFramesCount();
657   for ( int i = 0; i < nbSf; i++ ) {
658     QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
659     if ( sf->getTypeView() == VIEW_VTK ) {
660       vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
661       vtkActorCollection* theActors = Renderer->GetActors();
662       theActors->InitTraversal();
663       vtkActor *ac = theActors->GetNextActor();
664       while(!(ac==NULL)) {
665         if ( ac->IsA("GEOM_Actor") ) {
666           GEOM_Actor* anActor = GEOM_Actor::SafeDownCast( ac );
667           if ( anActor->hasIO() ) {
668             Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(anActor->getIO());
669             Standard_CString theIOR = GIO->getIOR();
670             if ( strcmp( IOR, theIOR ) == 0 ) {
671               if ( onlyInActiveView ) {
672                 if ( sf == GeomGUI->myActiveStudy->getActiveStudyFrame() ) {
673                   testResult = true;
674                   return anActor;
675                 }
676               } else {
677                 testResult = true;
678                 return anActor;
679               }
680             }
681           }
682         }
683         ac = theActors->GetNextActor();
684       }
685     }
686   }
687   testResult = false;
688   return GEOM_Actor::New();
689 }
690
691 //=======================================================================
692 // function : ConvertIOinGEOMShape()
693 // purpose  :
694 //=======================================================================
695 GEOM::GEOM_Shape_ptr GeometryGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO,
696                                                   Standard_Boolean& testResult )
697 {
698   GEOM::GEOM_Shape_ptr aShape ;
699   testResult = false ;
700
701   /* case SObject */
702   if ( IO->hasEntry() ) {
703     SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
704     SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
705     SALOMEDS::GenericAttribute_var anAttr;
706     SALOMEDS::AttributeIOR_var     anIOR;
707     if ( !obj->_is_nil() ) {
708        if (obj->FindAttribute(anAttr, "AttributeIOR")) {
709          anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
710          aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
711          testResult = true ;
712          return aShape;
713        }
714     }
715   }
716   /* case Graphical Object */
717   if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
718     Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
719     Standard_CString ior = GIObject->getIOR();
720     testResult = true ;
721     aShape = myComponentGeom->GetIORFromString(ior) ;
722     return aShape;
723   } 
724   return aShape ;
725 }
726
727
728 //=======================================================================
729 // function : ConvertListOfIOInListOfIOR()
730 // purpose  : 
731 //=======================================================================
732 void GeometryGUI::ConvertListOfIOInListOfIOR( const SALOME_ListIO& aList,
733                                               GEOM::GEOM_Gen::ListOfIOR& listIOR )
734 {
735   int nbSel = aList.Extent();  
736   listIOR.length(nbSel) ;
737   int j=0;
738   SALOME_ListIteratorOfListIO It( aList );
739   for ( int i=0; It.More(); It.Next(), i++ ) 
740     {
741       Handle(SALOME_InteractiveObject) IObject = It.Value();
742       
743       if ( IObject->hasEntry() ) 
744         {
745           SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
746           SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
747           SALOMEDS::GenericAttribute_var anAttr;
748           SALOMEDS::AttributeIOR_var     anIOR;
749           if ( !obj->_is_nil() && obj->FindAttribute(anAttr, "AttributeIOR") )
750             {
751               anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
752               ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
753               CORBA::ORB_var& _orb = init.orb() ;
754               CORBA::String_var theValue = anIOR->Value();
755               CORBA::Object_var theObj = _orb->string_to_object(theValue);
756               if (theObj->_is_a("IDL:GEOM/GEOM_Shape:1.0"))
757                 {
758                   listIOR[j] = strdup(theValue) ;
759                   j++;
760                 }
761             }
762         } 
763       else if ( IObject->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
764       Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IObject );
765       Standard_CString ior = GIObject->getIOR();
766       listIOR[j] = strdup(ior) ;
767       j++;
768     }
769   }
770   listIOR.length(j) ;
771 }
772
773
774 //=================================================================================
775 // function : GetShapeTypeString()
776 // purpose  : for a single shape
777 //=================================================================================
778 bool GeometryGUI::GetShapeTypeString( const TopoDS_Shape& aShape, Standard_CString& aTypeString )
779 {
780   if( aShape.IsNull() ) {
781     aTypeString = "aNullShape" ;
782     return false ;
783   }
784   switch (aShape.ShapeType() )
785   {
786   case TopAbs_COMPOUND:
787     { aTypeString = strdup(tr("GEOM_COMPOUND")) ; return true ; }
788   case  TopAbs_COMPSOLID:
789     { aTypeString = strdup(tr("GEOM_COMPOUNDSOLID")) ; return true ; }
790   case TopAbs_SOLID:
791     { aTypeString = strdup(tr("GEOM_SOLID")) ; return true ; }
792   case TopAbs_SHELL:
793     { aTypeString = strdup(tr("GEOM_SHELL")) ; return true ; }
794   case TopAbs_FACE:
795     { 
796       BRepAdaptor_Surface surf(TopoDS::Face(aShape));
797       if ( surf.GetType() == GeomAbs_Plane ) {
798         aTypeString = strdup(tr("GEOM_PLANE")) ;
799         return true ;
800       } else if ( surf.GetType() == GeomAbs_Cylinder ) {
801         aTypeString = strdup(tr("GEOM_SURFCYLINDER")) ;
802         return true ;
803       } else if ( surf.GetType() == GeomAbs_Sphere ) {
804         aTypeString = strdup(tr("GEOM_SURFSPHERE")) ;
805         return true ;
806       } else if ( surf.GetType() == GeomAbs_Torus ) {
807         aTypeString = strdup(tr("GEOM_SURFTORUS")) ;
808         return true ;
809       } else if ( surf.GetType() == GeomAbs_Cone ) {
810         aTypeString = strdup(tr("GEOM_SURFCONE")) ;
811         return true ;
812       } else {
813         aTypeString = strdup(tr("GEOM_FACE")) ;
814         return true ;
815       }
816     }
817   case TopAbs_WIRE:
818     { aTypeString = strdup(tr("GEOM_WIRE")) ; return true ; }
819   case TopAbs_EDGE:
820     { 
821       BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
822       if ( curv.GetType() == GeomAbs_Line ) {
823         if ( (Abs(curv.FirstParameter()) >= 1E6 ) || 
824              (Abs(curv.LastParameter()) >= 1E6 )) {
825           aTypeString = strdup(tr("GEOM_LINE")) ;
826         } else
827           aTypeString = strdup(tr("GEOM_EDGE")) ;
828         return true ;
829       } else if ( curv.GetType() == GeomAbs_Circle ) {
830         if ( curv.IsClosed() )
831           aTypeString = strdup(tr("GEOM_CIRCLE")) ;
832         else
833           aTypeString = strdup(tr("GEOM_ARC")) ;
834         return true ;
835       } else {
836         aTypeString = strdup(tr("GEOM_EDGE")) ;
837         return true ;
838       }
839     }
840   case TopAbs_VERTEX:
841     { aTypeString = strdup(tr("GEOM_VERTEX")) ; return true ; }
842   case TopAbs_SHAPE:
843     { aTypeString = strdup(tr("GEOM_SHAPE")) ; return true ; }
844   }
845   return false ;
846 }
847
848
849 //=================================================================================
850 // function : CreateArrowForLinearEdge()
851 // purpose  : Create a cone topology to be used to display an arrow in the middle
852 //          : of an edge showing its orientation. (For simulation and Viewer OCC only)
853 //=================================================================================
854 bool GeometryGUI::CreateArrowForLinearEdge( const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone )
855 {
856   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_OCC || tds.ShapeType() != TopAbs_EDGE )
857     return false;
858   
859   OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
860   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
861   Standard_Real Width, Height ;
862   view3d->Size(Width, Height) ;
863   const Standard_Real aHeight = (Width + Height) / 50.0 ;
864   
865   try {
866     Standard_Real first, last ;
867     Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
868     if( !curv->IsCN(1) )
869       return false ;
870     
871     const Standard_Real param = (first+last) / 2.0 ;
872     gp_Pnt middleParamPoint ;
873     gp_Vec V1 ;
874     curv->D1( param, middleParamPoint, V1) ;
875     if ( V1.Magnitude() < Precision::Confusion() )
876       return false ;
877     
878     /* Topology orientation not geom orientation */
879     if( tds.Orientation() == TopAbs_REVERSED )
880       V1 *= -1.0 ;
881     
882     gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1) ) ;
883     const Standard_Real radius1 = aHeight / 5.0 ;
884     if( radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion() ) {
885       ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape() ;
886       return true ;
887     }
888   }
889   catch(Standard_Failure) {
890     // OCC failures are hard to catch in GUI.
891     // This  because of the position for  #include <Standard_ErrorHandler.hxx> that is very critic to find 
892     // in SALOME environment : compilation error !
893   }
894   return false ;
895 }
896
897
898 //=======================================================================
899 // function : SelectionByNameInDialogs()
900 // purpose  : Called when user has entered a name of object in a LineEdit.
901 //          : The selection is changed. Dialog box will receive the 
902 //          : corresponding signal to manage this event.
903 //=======================================================================
904 bool GeometryGUI::SelectionByNameInDialogs( QWidget* aWidget, const QString& objectUserName, SALOME_Selection* Sel )
905 {
906   
907   /* Find SObject with name in component GEOM */
908   SALOMEDS::Study_var ST = this->myActiveStudy->getStudyDocument() ;
909   SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
910   listSO = ST->FindObjectByName( objectUserName, "GEOM" ) ;
911   
912   if ( listSO->length() < 1 ) {
913     const QString caption  = tr("GEOM_WRN_WARNING") ;
914     const QString text = tr("GEOM_NAME_INCORRECT") ;
915     const QString button0  = tr("GEOM_BUT_OK") ;
916     QMessageBox::warning( aWidget, caption, text, button0 ) ;
917     return false ;
918   }
919   /* More than one object with same name */
920   if ( listSO->length() > 1 ) {
921     const QString caption  = tr("GEOM_WRN_WARNING") ;
922     const QString text = tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE") ;
923     const QString button0  = tr("GEOM_BUT_OK") ;
924     QMessageBox::warning( aWidget, caption, text, button0 ) ;
925     return false ;
926   }
927
928   SALOMEDS::SObject_var theObj = listSO[0] ;
929   /* Create a SALOME_InteractiveObject with a SALOME::SObject */
930   Standard_CString anEntry = theObj->GetID() ;
931   Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject( anEntry, "GEOM", strdup(objectUserName) ) ;
932
933   /* Add as a selected object       */
934   /* Clear any previous selection : */
935   /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */ 
936   Sel->ClearIObjects() ; 
937   Sel->AddIObject( SI ) ;
938   return true ;
939 }
940
941
942 //=======================================================================
943 // function : MakePointAndDisplay
944 // purpose  : 
945 //=======================================================================
946 void GeometryGUI::MakePointAndDisplay( const double x, const double y, const double z ) 
947 {
948   try {
949     GEOM::GEOM_Shape_var P = myComponentGeom->MakeVertex( x, y, z );
950     P->NameType( tr("GEOM_VERTEX") );
951     if ( Display( P, "") )
952       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
953   }  
954   catch (const SALOME::SALOME_Exception& S_ex) {
955     QtCatchCorbaException(S_ex);
956   }
957   return ;
958 }
959
960
961
962 //=======================================================================
963 // function : MakeVectorAndDisplay()
964 // purpose  : 
965 //=======================================================================
966 void GeometryGUI::MakeVectorAndDisplay( const gp_Pnt P1, const gp_Pnt P2 )
967 {
968   try {
969     GEOM::PointStruct pstruct1 = myComponentGeom->MakePointStruct( P1.X(), P1.Y(), P1.Z() ) ;
970     GEOM::PointStruct pstruct2 = myComponentGeom->MakePointStruct( P2.X(), P2.Y(), P2.Z() ) ;
971     GEOM::GEOM_Shape_var Vector = myComponentGeom->MakeVector( pstruct1, pstruct2 );
972     Vector->NameType(tr("GEOM_VECTOR"));
973     if ( Display( Vector, "") )
974       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
975   }
976   catch (const SALOME::SALOME_Exception& S_ex) {
977     QtCatchCorbaException(S_ex);
978   }
979 }
980
981
982 //=======================================================================
983 // function : MakeBoxAndDisplay()
984 // purpose  : 
985 //=======================================================================
986 void GeometryGUI::MakeBoxAndDisplay( const gp_Pnt P1, const gp_Pnt P2 )
987 {
988   try {
989     GEOM::GEOM_Shape_var box = myComponentGeom->MakeBox( P1.X(), P1.Y(), P1.Z(), P2.X(), P2.Y(), P2.Z() );
990     box->NameType(tr("GEOM_BOX"));
991     if ( Display( box, "") ) {
992       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
993     }
994   }
995   catch (const SALOME::SALOME_Exception& S_ex) {
996     QtCatchCorbaException(S_ex);
997   }
998 }
999
1000
1001
1002
1003 //=======================================================================
1004 // function : MakePlaneAndDisplay()
1005 // purpose  : Plane point is P1 and dx, dy, dz define a normal vector
1006 //=======================================================================
1007 void GeometryGUI::MakePlaneAndDisplay( const gp_Pnt P1,        const Standard_Real dx,
1008                                        const Standard_Real dy, const Standard_Real dz,
1009                                        const Standard_Real TrimSize )
1010 {
1011   try {
1012     gp_Dir aDirection;
1013     aDirection.SetCoord(dx, dy, dz) ;
1014     gp_Ax2 Axis( P1, aDirection );
1015     
1016     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z() ) ;
1017     GEOM::PointStruct d = myComponentGeom->MakePointStruct(aDirection.X(), aDirection.Y(), aDirection.Z()) ;
1018     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1019     GEOM::GEOM_Shape_ptr plane = myComponentGeom->MakePlane(pstruct, dstruct, TrimSize) ;
1020     plane->NameType(tr("GEOM_PLANE"));
1021     if ( Display( plane, "") )
1022       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1023   }
1024   catch (const SALOME::SALOME_Exception& S_ex) {
1025     QtCatchCorbaException(S_ex);
1026   }
1027 }
1028
1029
1030 //=======================================================================
1031 // function : MakeWorkingPlane()
1032 // purpose  : Change the point of view3d
1033 //=======================================================================
1034 void GeometryGUI::MakeWorkingPlane( const gp_Pnt P, const gp_Dir D)
1035 {
1036   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_OCC) {
1037     GeomGUI->myDesktop->putInfo( tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
1038     return ;
1039   }
1040   OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
1041   Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
1042   view3d->SetAt( P.X(), P.Y(), P.Z() );
1043   view3d->SetProj( D.X(), D.Y(), D.Z() );
1044   myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1045 }
1046
1047
1048 //=======================================================================
1049 // function : MakePrismAndDisplay()
1050 // purpose  : P1 and P2 is to define a vector for prism
1051 //=======================================================================
1052 void GeometryGUI::MakePrismAndDisplay( GEOM::GEOM_Shape_ptr BaseShape, const gp_Pnt P1, const gp_Pnt P2 )
1053 {
1054   try {
1055     GEOM::PointStruct PS1 = myComponentGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z() ) ;
1056     GEOM::PointStruct PS2 = myComponentGeom->MakePointStruct(P2.X(), P2.Y(), P2.Z() ) ;
1057     if( BaseShape->_is_nil() ) {
1058       myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; 
1059       return ;
1060     }
1061     
1062     GEOM::GEOM_Shape_ptr result = myComponentGeom->MakePrism( BaseShape, PS1, PS2 ) ;
1063     if (result->_is_nil()) {
1064       myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; 
1065       return ;
1066     }  
1067
1068     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
1069     Standard_CString type;
1070     GetShapeTypeString(S,type);
1071     result->NameType( type );
1072
1073     if ( Display( result, "") )
1074       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1075   }
1076   catch (const SALOME::SALOME_Exception& S_ex) {
1077     QtCatchCorbaException(S_ex);
1078   }
1079   return ;
1080 }
1081
1082
1083 //=====================================================================================
1084 // function : MakeLineAndDisplay()
1085 // purpose  : Create an infinite oriented line (linear edge in fact) 
1086 //=====================================================================================
1087 void GeometryGUI::MakeLineAndDisplay( const gp_Pnt InitPoint, const gp_Pnt LastPoint )
1088 {
1089   gp_Pnt P1,P2;  
1090   double dx, dy, dz ;
1091   GetBipointDxDyDz( InitPoint, LastPoint, dx, dy, dz ) ;
1092   Standard_Real length = InitPoint.Distance(LastPoint) ;
1093   if( length <= Precision::Confusion() ) {
1094     myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1095     return ;
1096   }
1097   
1098   Standard_Real coeff = 1E6 / length ;
1099   
1100   /* To create a line with length = 1E6     */
1101   /* Precision::Infinite() is 1E100 in OCC  */
1102   P1.SetX( InitPoint.X() - (coeff * dx) ) ;
1103   P1.SetY( InitPoint.Y() - (coeff * dy) ) ;
1104   P1.SetZ( InitPoint.Z() - (coeff * dz) ) ;
1105   
1106   P2.SetX( LastPoint.X() + (coeff * dx) ) ;
1107   P2.SetY( LastPoint.Y() + (coeff * dy) ) ;
1108   P2.SetZ( LastPoint.Z() + (coeff * dz) ) ;
1109   
1110   try {
1111     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z()) ;
1112     GEOM::PointStruct d = myComponentGeom->MakePointStruct(P2.X(), P2.Y(), P2.Z()) ;
1113     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1114     
1115     GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeLine(pstruct, dstruct) ;
1116     if(result->_is_nil()) {
1117       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1118       return ;
1119     }
1120     result->NameType(tr("GEOM_LINE"));
1121     
1122     if ( Display( result, "") )
1123       myDesktop->putInfo(tr("GEOM_PRP_READY"));
1124   }
1125   catch (const SALOME::SALOME_Exception& S_ex) {
1126     QtCatchCorbaException(S_ex);
1127   }
1128   return ;
1129 }
1130
1131
1132
1133 //=======================================================================
1134 // function : MakeBooleanAndDisplay()
1135 // purpose  : 
1136 //=======================================================================
1137 void GeometryGUI::MakeBooleanAndDisplay( GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2, const short operation )
1138 {
1139   try {
1140     GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeBoolean( Shape1, Shape2, operation ) ;
1141     if (result->_is_nil()) {
1142       myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; 
1143       return ;
1144     }  
1145
1146     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
1147     Standard_CString type;
1148     GetShapeTypeString(S,type);
1149     result->NameType( type );
1150
1151     if ( Display( result, "") )
1152       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1153   }
1154   catch (const SALOME::SALOME_Exception& S_ex) {
1155     QtCatchCorbaException(S_ex);
1156   }
1157   return ;
1158 }
1159
1160
1161 //=====================================================================================
1162 // function : MakeSphere()
1163 // purpose  :
1164 //=====================================================================================
1165 void GeometryGUI::MakeSphereAndDisplay( const gp_Pnt aCenterPoint, const double aRadius )
1166 {
1167   try {
1168     if( aRadius <= Precision::Confusion() ) {
1169       QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("GEOM_WRN_WARNING"),
1170                               tr ("GEOM_WRN_RADIUS_NULL"),   tr ("GEOM_BUT_YES") );
1171       return ;
1172     }
1173     GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeSphere(aCenterPoint.X(),aCenterPoint.Y(),aCenterPoint.Z(), aRadius);
1174     result->NameType(tr("GEOM_SPHERE"));
1175     if ( Display( result, "") )
1176       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1177   }
1178   catch (const SALOME::SALOME_Exception& S_ex) {
1179     QtCatchCorbaException(S_ex);
1180   }
1181   return ;
1182 }
1183
1184
1185 //=====================================================================================
1186 // function : MakeConeAndDisplay()
1187 // purpose  :
1188 //=====================================================================================
1189 void GeometryGUI::MakeConeAndDisplay( const gp_Pnt BasePoint,
1190                                       const gp_Dir aDir,
1191                                       const double Radius1,
1192                                       const double Radius2,
1193                                       const double aHeight )
1194 {
1195   try {
1196     if( ( Radius1 <= Precision::Confusion() && Radius2 <= Precision::Confusion() ) || aHeight <= Precision::Confusion() )
1197       return ;
1198     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( BasePoint.X(), BasePoint.Y(), BasePoint.Z() ) ;
1199     GEOM::PointStruct d = myComponentGeom->MakePointStruct( aDir.X(), aDir.Y(), aDir.Z() ) ;
1200     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1201     
1202     GEOM::GEOM_Shape_var result = myComponentGeom->MakeCone( pstruct, dstruct, Radius1, Radius2, aHeight ) ;  
1203     if ( result->_is_nil() ) {
1204       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1205       return  ;
1206     }
1207     result->NameType(tr("GEOM_CONE"));
1208     if ( Display( result, "") )
1209       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1210   } 
1211   catch (const SALOME::SALOME_Exception& S_ex) {
1212     QtCatchCorbaException(S_ex);
1213   }
1214   return  ;
1215 }
1216
1217
1218 //=====================================================================================
1219 // function : MakeCylinderAndDisplay()
1220 // purpose  :
1221 //=====================================================================================
1222 void GeometryGUI::MakeCylinderAndDisplay( const gp_Pnt BasePoint,
1223                                           const gp_Dir aDir,
1224                                           const double Radius,
1225                                           const double aHeight )
1226 {
1227   try {
1228     if( Radius <= Precision::Confusion() || aHeight <= Precision::Confusion() )
1229       return ;
1230     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( BasePoint.X(), BasePoint.Y(), BasePoint.Z() ) ;
1231     GEOM::PointStruct d = myComponentGeom ->MakePointStruct( aDir.X(), aDir.Y(), aDir.Z() ) ;
1232     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1233     
1234     GEOM::GEOM_Shape_var result = myComponentGeom->MakeCylinder(pstruct, dstruct, Radius, aHeight) ;
1235     if ( result->_is_nil() ) {
1236       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1237       return  ;
1238     }
1239     result->NameType(tr("GEOM_CYLINDER"));
1240     if ( Display( result, "") )
1241       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1242   }
1243   catch (const SALOME::SALOME_Exception& S_ex) {
1244     QtCatchCorbaException(S_ex);
1245   }
1246   return  ;
1247 }
1248
1249
1250 //=====================================================================================
1251 // function : MakeTorusAndDisplay()
1252 // purpose  :
1253 //=====================================================================================
1254 void GeometryGUI::MakeTorusAndDisplay( const gp_Pnt BasePoint,
1255                                        const gp_Dir aDir,
1256                                        const double Radius1,
1257                                        const double Radius2 )
1258 {
1259   try {
1260     if( Radius1 <= Precision::Confusion() || Radius2 <= Precision::Confusion() )
1261       return ;
1262     
1263     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( BasePoint.X(), BasePoint.Y(), BasePoint.Z() ) ;
1264     GEOM::PointStruct d = myComponentGeom ->MakePointStruct( aDir.X(), aDir.Y(), aDir.Z() ) ;
1265     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1266     
1267     GEOM::GEOM_Shape_var result = myComponentGeom->MakeTorus(pstruct, dstruct, Radius1, Radius2) ;
1268     if ( result->_is_nil() ) {
1269       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1270       return  ;
1271     }
1272     result->NameType(tr("GEOM_TORUS"));
1273     if ( Display( result, "") )
1274       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1275   }
1276   catch (const SALOME::SALOME_Exception& S_ex) {
1277     QtCatchCorbaException(S_ex);
1278   }
1279   return  ;
1280 }
1281
1282
1283 //=====================================================================================
1284 // function : MakePipeAndDisplay()
1285 // purpose  :
1286 //=====================================================================================
1287 void GeometryGUI::MakePipeAndDisplay( GEOM::GEOM_Shape_ptr aPath, GEOM::GEOM_Shape_ptr aBase ) 
1288 {
1289   try {
1290     GEOM::GEOM_Shape_ptr result = myComponentGeom->MakePipe(aPath, aBase);
1291     if ( !result->_is_nil() && Display( result, "") ) {
1292
1293       TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
1294       Standard_CString type;
1295       GetShapeTypeString(S,type);
1296       result->NameType( type );
1297
1298       myDesktop->putInfo( tr("GEOM_PRP_DONE") );
1299     }
1300     else {
1301       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1302     }
1303   }
1304   catch (const SALOME::SALOME_Exception& S_ex) {
1305     QtCatchCorbaException(S_ex);
1306   }
1307   return ;
1308 }
1309
1310
1311 //=====================================================================================
1312 // function : MakeFillingAndDisplay()
1313 // purpose  :
1314 //=====================================================================================
1315 void GeometryGUI::MakeFillingAndDisplay( GEOM::GEOM_Shape_ptr SectionShape, 
1316                                          const short mindeg,
1317                                          const short maxdeg,
1318                                          const double tol3d, 
1319                                          const double tol2d, 
1320                                          const short nbiter )
1321 {  
1322   try {
1323     GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeFilling( SectionShape,
1324                                                           mindeg, maxdeg,
1325                                                           tol3d, tol2d, nbiter );
1326     if (result->_is_nil()) {
1327       myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; 
1328       return ;
1329     }  
1330
1331     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
1332     Standard_CString type;
1333     GetShapeTypeString(S,type);
1334     result->NameType( type );
1335
1336     if ( Display( result, "") )
1337       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1338     return ;  
1339   } 
1340   catch (const SALOME::SALOME_Exception& S_ex) {
1341     QtCatchCorbaException(S_ex);
1342   }
1343 }
1344
1345
1346
1347 //=====================================================================================
1348 // function : MakeMirrorAndDisplay()
1349 // purpose  :
1350 //=====================================================================================
1351 void GeometryGUI::MakeMirrorAndDisplay( GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2 )
1352 {
1353   try {
1354     GEOM::GEOM_Shape_var result  = myComponentGeom->MakeMirrorByPlane( Shape1, Shape2 );
1355     if (result->_is_nil()) {
1356       myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; 
1357       return ;
1358     }  
1359     result->NameType( Shape1->NameType() );
1360     if ( Display( result, "") )
1361       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1362   }
1363   catch (const SALOME::SALOME_Exception& S_ex) {
1364     QtCatchCorbaException(S_ex);
1365   }
1366   return ;
1367 }
1368
1369
1370 //=====================================================================================
1371 // function : MakeSewingAndDisplay()
1372 // purpose  :
1373 //=====================================================================================
1374 void GeometryGUI::MakeSewingAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR,
1375                                         const Standard_Real precision )
1376 {
1377   try {
1378     GEOM::GEOM_Shape_var result = myComponentGeom->MakeSewing(listShapesIOR, precision) ;
1379     if( result->_is_nil() ) {
1380       myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ;
1381       return ;
1382     }
1383
1384     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
1385     Standard_CString type;
1386     GetShapeTypeString(S,type);
1387     result->NameType( type );
1388
1389     if( Display( result, "") )
1390       myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ;
1391     return ;
1392   }
1393   catch (const SALOME::SALOME_Exception& S_ex) {
1394     QtCatchCorbaException(S_ex);
1395   }
1396 }
1397
1398
1399 //=====================================================================================
1400 // function : MakeCompoundAndDisplay()
1401 // purpose  :
1402 //=====================================================================================
1403 void GeometryGUI::MakeCompoundAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR )
1404 {
1405   try {
1406     GEOM::GEOM_Shape_var result = myComponentGeom->MakeCompound(listShapesIOR) ;
1407     if( result->_is_nil() ) {
1408       myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ;
1409       return ;
1410     }
1411     result->NameType(tr("GEOM_COMPOUND"));
1412     if( Display( result, "" ))
1413       myDesktop->putInfo(tr("GEOM_PRP_DONE")) ;
1414   }
1415   catch (const SALOME::SALOME_Exception& S_ex) {
1416     QtCatchCorbaException(S_ex);
1417   }
1418   return ;
1419 }
1420
1421
1422 //=====================================================================================
1423 // function : MakeFaceAndDisplay()
1424 // purpose  :
1425 //=====================================================================================
1426 void GeometryGUI::MakeFaceAndDisplay( GEOM::GEOM_Shape_ptr aWire, const Standard_Boolean wantPlanar )
1427 {
1428   try {
1429     GEOM::GEOM_Shape_var result = myComponentGeom->MakeFace( aWire, wantPlanar) ;
1430     if( result->_is_nil() ) {
1431       myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ;
1432       return ;
1433     }
1434     if ( wantPlanar )
1435       result->NameType(tr("GEOM_PLANE"));
1436     else
1437       result->NameType(tr("GEOM_FACE"));
1438     if( Display( result, "") )
1439       myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ;
1440   }
1441   catch (const SALOME::SALOME_Exception& S_ex) {
1442     QtCatchCorbaException(S_ex);
1443   }
1444   return ;
1445 }
1446
1447
1448
1449 //=====================================================================================
1450 // function : MakeLinearEdgeAndDisplay()
1451 // purpose  :
1452 //=====================================================================================
1453 void GeometryGUI::MakeLinearEdgeAndDisplay( const gp_Pnt P1, const gp_Pnt P2 )
1454 {
1455   try {
1456     GEOM::PointStruct ps1 = myComponentGeom->MakePointStruct( P1.X(), P1.Y(), P1.Z() ) ;
1457     GEOM::PointStruct ps2 = myComponentGeom->MakePointStruct( P2.X(), P2.Y(), P2.Z() ) ;
1458     GEOM::GEOM_Shape_var result = myComponentGeom->MakeEdge( ps1, ps2 ) ;
1459     if( result->_is_nil() ) {
1460       myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ;
1461       return ;
1462     }
1463     result->NameType(tr("GEOM_EDGE"));
1464     if( Display( result, "") )
1465       myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ;
1466   }
1467   catch(const SALOME::SALOME_Exception& S_ex) {
1468     QtCatchCorbaException(S_ex);
1469   }
1470   return ;
1471 }
1472
1473
1474 //=====================================================================================
1475 // function : MakeOrientationChangeAndDisplay()
1476 // purpose  :
1477 //=====================================================================================
1478 void GeometryGUI::MakeOrientationChangeAndDisplay( GEOM::GEOM_Shape_ptr Shape )
1479 {
1480   try {
1481     GEOM::GEOM_Shape_var result = myComponentGeom->OrientationChange( Shape ) ;
1482     if( result->_is_nil() ) {
1483       myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ;
1484       return ;
1485     }
1486     result->NameType( Shape->NameType() );
1487     if ( Display( result, "" ))
1488       myDesktop->putInfo(tr("GEOM_PRP_DONE")); 
1489     return ;
1490   }
1491   catch (const SALOME::SALOME_Exception& S_ex) {
1492     QtCatchCorbaException(S_ex);
1493   }
1494 }
1495
1496
1497 //=====================================================================================
1498 // function : MakeScaleAndDisplay()
1499 // purpose  :
1500 //=====================================================================================
1501 void GeometryGUI::MakeScaleAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Pnt centralPoint, const Standard_Real factor )
1502 {
1503   try {
1504     GEOM::PointStruct P = myComponentGeom->MakePointStruct(centralPoint.X(), centralPoint.Y(), centralPoint.Z() ) ;
1505     GEOM::GEOM_Shape_var result = myComponentGeom->MakeScaleTransform(Shape, P, factor) ;
1506     //    result->NameType(tr("GEOM_SCALE"));
1507     result->NameType( Shape->NameType() );
1508     if ( Display( result, "") )
1509       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1510     else 
1511       myDesktop->putInfo (tr("GEOM_PRP_NULLSHAPE")) ; 
1512   }
1513   catch (const SALOME::SALOME_Exception& S_ex) {
1514     QtCatchCorbaException(S_ex);
1515   }
1516   return ;
1517 }
1518
1519
1520 //=======================================================================================
1521 // function : MakeRevolutionAndDisplay()
1522 // purpose  :
1523 //=======================================================================================
1524 void GeometryGUI::MakeRevolutionAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Pnt loc, const gp_Dir dir, const Standard_Real revolAngle )
1525 {
1526   try {
1527     GEOM::AxisStruct axis = myComponentGeom->MakeAxisStruct(loc.X(), loc.Y(), loc.Z(), dir.X(), dir.Y(), dir.Z() ) ;
1528     GEOM::GEOM_Shape_ptr result = myComponentGeom->MakeRevolution(Shape, axis, revolAngle) ;
1529     if ( result->_is_nil() ) {
1530       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1531       return  ;
1532     }
1533
1534     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
1535     Standard_CString type;
1536     GetShapeTypeString(S,type);
1537     result->NameType( type );
1538
1539     if ( Display( result ) )
1540       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1541   }
1542   catch (const SALOME::SALOME_Exception& S_ex) {
1543     QtCatchCorbaException(S_ex);
1544   }
1545   return  ;
1546 }
1547
1548
1549 //=======================================================================================
1550 // function : MakeRotationAndDisplay()
1551 // purpose  :
1552 //=======================================================================================
1553 void GeometryGUI::MakeRotationAndDisplay( GEOM::GEOM_Shape_ptr Shape,
1554                                           const gp_Pnt loc,
1555                                           const gp_Dir dir,
1556                                           const Standard_Real angle )
1557 {
1558   try {
1559     const GEOM::AxisStruct axis = myComponentGeom->MakeAxisStruct(loc.X(), loc.Y(), loc.Z(), dir.X(), dir.Y(), dir.Z() ) ;
1560     GEOM::GEOM_Shape_var result = myComponentGeom->MakeRotation(Shape, axis, angle);
1561     if ( result->_is_nil() ) {
1562       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
1563       return ;
1564     }
1565     result->NameType( Shape->NameType() );
1566     if ( Display( result ) )
1567       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1568   }
1569   catch (const SALOME::SALOME_Exception& S_ex) {
1570     QtCatchCorbaException(S_ex);
1571   }  
1572   return  ;
1573 }
1574
1575
1576 //=================================================================================
1577 // function : MakeTranslationAndDisplay()
1578 // purpose  : Translate a shape
1579 //=================================================================================
1580 void GeometryGUI::MakeTranslationAndDisplay( GEOM::GEOM_Shape_ptr Shape, gp_Vec V )
1581 {
1582   try {
1583     GEOM::GEOM_Shape_var result = myComponentGeom->MakeTranslation( Shape, V.X(), V.Y(), V.Z() ) ;
1584     if ( result->_is_nil() ) {
1585       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
1586       return ;
1587     }
1588     result->NameType( Shape->NameType() );
1589     if ( Display( result ) )
1590       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1591   }  
1592   catch (const SALOME::SALOME_Exception& S_ex) {
1593     QtCatchCorbaException(S_ex);
1594   }
1595   return  ;
1596 }
1597
1598 //=================================================================================
1599 // function : MakeMultiTranslation1DAndDisplay()
1600 // purpose  : Multi-Translate a shape
1601 //=================================================================================
1602 void GeometryGUI::MakeMultiTranslation1DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const double Step, const short NbTimes ) 
1603 {
1604   try {
1605     GEOM::PointStruct d = myComponentGeom->MakePointStruct( Dir.X(), Dir.Y(), Dir.Z() ) ;
1606     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1607
1608     GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiTranslation1D( Shape, dstruct, Step, NbTimes );
1609     if ( result->_is_nil() ) {
1610       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
1611       return ;
1612     }
1613     result->NameType( tr("GEOM_COMPOUND") );
1614     if ( Display( result ) )
1615       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1616   }  
1617   catch (const SALOME::SALOME_Exception& S_ex) {
1618     QtCatchCorbaException(S_ex);
1619   }
1620   return  ;
1621 }
1622
1623
1624 //=================================================================================
1625 // function : MakeMultiTranslation2DAndDisplay()
1626 // purpose  : Multi-Translate a shape
1627 //=================================================================================
1628 void GeometryGUI::MakeMultiTranslation2DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir1, const double Step1, const short NbTimes1, const gp_Dir Dir2, const double Step2, const short NbTimes2 ) 
1629 {
1630   try {
1631     GEOM::PointStruct d1 = myComponentGeom->MakePointStruct( Dir1.X(), Dir1.Y(), Dir1.Z() ) ;
1632     GEOM::DirStruct dstruct1 = myComponentGeom->MakeDirection(d1) ;
1633     GEOM::PointStruct d2 = myComponentGeom->MakePointStruct( Dir2.X(), Dir2.Y(), Dir2.Z() ) ;
1634     GEOM::DirStruct dstruct2 = myComponentGeom->MakeDirection(d2) ;
1635
1636     GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiTranslation2D( Shape, dstruct1, Step1, NbTimes1, dstruct2, Step2, NbTimes2 );
1637     if ( result->_is_nil() ) {
1638       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
1639       return ;
1640     }
1641     result->NameType( tr("GEOM_COMPOUND") );
1642     if ( Display( result ) )
1643       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1644   }  
1645   catch (const SALOME::SALOME_Exception& S_ex) {
1646     QtCatchCorbaException(S_ex);
1647   }
1648   return  ;
1649 }
1650
1651
1652 //=================================================================================
1653 // function : MakeMultiRotation1DAndDisplay()
1654 // purpose  : Multi-Rotate a shape
1655 //=================================================================================
1656 void GeometryGUI::MakeMultiRotation1DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const gp_Pnt Loc, const short NbTimes ) 
1657 {
1658   try {
1659     GEOM::PointStruct d = myComponentGeom->MakePointStruct( Dir.X(), Dir.Y(), Dir.Z() ) ;
1660     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1661     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( Loc.X(), Loc.Y(), Loc.Z() ) ;
1662
1663     GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiRotation1D( Shape, dstruct, pstruct, NbTimes );
1664     if ( result->_is_nil() ) {
1665       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
1666       return ;
1667     }
1668     result->NameType( tr("GEOM_COMPOUND") );
1669     if ( Display( result ) )
1670       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1671   }  
1672   catch (const SALOME::SALOME_Exception& S_ex) {
1673     QtCatchCorbaException(S_ex);
1674   }
1675   return  ;
1676 }
1677
1678
1679 //=================================================================================
1680 // function : MakeMultiRotation2DAndDisplay()
1681 // purpose  : Multi-Rotate a shape
1682 //=================================================================================
1683 void GeometryGUI::MakeMultiRotation2DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const gp_Pnt Loc, const double Ang, const short NbTimes1, const double Step, const short NbTimes2 ) 
1684 {
1685   try {
1686     GEOM::PointStruct d = myComponentGeom->MakePointStruct( Dir.X(), Dir.Y(), Dir.Z() ) ;
1687     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1688     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( Loc.X(), Loc.Y(), Loc.Z() ) ;
1689
1690     GEOM::GEOM_Shape_var result = myComponentGeom->MakeMultiRotation2D( Shape, dstruct, pstruct, Ang, NbTimes1, Step, NbTimes2 );
1691     if ( result->_is_nil() ) {
1692       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
1693       return ;
1694     }
1695     result->NameType( tr("GEOM_COMPOUND") );
1696     if ( Display( result ) )
1697       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1698   }  
1699   catch (const SALOME::SALOME_Exception& S_ex) {
1700     QtCatchCorbaException(S_ex);
1701   }
1702   return  ;
1703 }
1704
1705
1706
1707 //=======================================================================================
1708 // function : MakeArcAndDisplay()
1709 // purpose  : Make an arc of circle from InitPoint to CirclePoint and passing on EndPoint
1710 //=======================================================================================
1711 void GeometryGUI::MakeArcAndDisplay( gp_Pnt InitPoint, gp_Pnt CirclePoint, gp_Pnt EndPoint )
1712 {
1713   gp_Vec v1( CirclePoint, InitPoint ) ;
1714   gp_Vec v2( CirclePoint, EndPoint ) ;
1715   if( v1.IsParallel(v2, Precision::Angular() ) )
1716     return ;
1717   
1718   try { 
1719     GEOM::PointStruct pI = myComponentGeom->MakePointStruct( InitPoint.X(), InitPoint.Y(), InitPoint.Z() );
1720     GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CirclePoint.X(), CirclePoint.Y(), CirclePoint.Z() );
1721     GEOM::PointStruct pE = myComponentGeom->MakePointStruct( EndPoint.X(), EndPoint.Y(), EndPoint.Z() );
1722     GEOM::GEOM_Shape_var result = myComponentGeom->MakeArc(pI, pC, pE) ;
1723     if ( result->_is_nil() ) {
1724       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
1725       return  ;
1726     }
1727     result->NameType(tr("GEOM_ARC"));
1728     if ( Display(  result ) )
1729       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1730   }
1731   catch (const SALOME::SALOME_Exception& S_ex) {
1732     QtCatchCorbaException(S_ex);
1733   }    
1734   return ;
1735 }
1736
1737
1738 //=====================================================================================
1739 // function : MakeCircleAndDisplay()
1740 // purpose  :
1741 //=====================================================================================
1742 void GeometryGUI::MakeCircleAndDisplay( const gp_Pnt CenterPoint, const gp_Dir dir, const Standard_Real Radius )
1743 {
1744   try {
1745     GEOM::PointStruct pstruct = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(),  CenterPoint.Z() ) ;
1746     GEOM::PointStruct d = myComponentGeom->MakePointStruct( dir.X(), dir.Y(), dir.Z() ) ;
1747     GEOM::DirStruct dstruct = myComponentGeom->MakeDirection(d) ;
1748     
1749     GEOM::GEOM_Shape_var result = myComponentGeom->MakeCircle(pstruct, dstruct, Radius) ;
1750     if ( result->_is_nil() ) {
1751       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
1752       return ;
1753     }
1754     result->NameType(tr("GEOM_CIRCLE"));
1755     if ( Display( result ) )
1756       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
1757   }
1758   catch (const SALOME::SALOME_Exception& S_ex) {
1759     QtCatchCorbaException(S_ex);
1760   }
1761   return  ;
1762 }
1763
1764
1765
1766 //=====================================================================================
1767 // function : MakeWireAndDisplay()
1768 // purpose  :
1769 //=====================================================================================
1770 void GeometryGUI::MakeWireAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR )
1771 {
1772   try {
1773     GEOM::GEOM_Shape_var result = myComponentGeom->MakeWire(listShapesIOR) ;
1774     if( result->_is_nil() ) {
1775       myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ;
1776       return ;
1777     }
1778     result->NameType(tr("GEOM_WIRE"));
1779     if( Display( result, "") )
1780       myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ;
1781   }
1782   catch (const SALOME::SALOME_Exception& S_ex) {
1783     QtCatchCorbaException(S_ex);
1784   }
1785   return ;
1786 }
1787
1788
1789 //=====================================================================================
1790 // function : MakePartitionAndDisplay()
1791 // purpose  :
1792 //=====================================================================================
1793 void GeometryGUI::MakePartitionAndDisplay (const GEOM::GEOM_Gen::ListOfIOR& listShapesIOR,
1794                                            const GEOM::GEOM_Gen::ListOfIOR& listToolsIOR,
1795                                            const GEOM::GEOM_Gen::ListOfIOR& listKeepInsIOR,
1796                                            const GEOM::GEOM_Gen::ListOfIOR& listRemoveInsIOR,
1797                                            const GEOM::shape_type           limit)
1798 {
1799   try {
1800     GEOM::GEOM_Shape_var result = myComponentGeom->Partition(listShapesIOR,
1801                                                              listToolsIOR,
1802                                                              listKeepInsIOR,
1803                                                              listRemoveInsIOR,
1804                                                              (CORBA::Short) limit);
1805     if( result->_is_nil() ) {
1806       myDesktop->putInfo(tr("GEOM_PRP_NULLSHAPE")) ;
1807       return ;
1808     }
1809     result->NameType(tr("GEOM_PARTITION"));
1810     if( Display( result, "") )
1811       myDesktop ->putInfo(tr("GEOM_PRP_DONE")) ;
1812     return ;
1813   }
1814   catch (const SALOME::SALOME_Exception& S_ex) {
1815     QtCatchCorbaException(S_ex);
1816   }
1817 }
1818
1819 //=======================================================================
1820 // function : SetState()
1821 // purpose  : Sets myState = aState a private field indicating which methode is active
1822 //=======================================================================
1823 void GeometryGUI::SetState(int aState )
1824 {  this->myState = aState ;  return ; }
1825
1826
1827 //=======================================================================
1828 // function : ResetState()
1829 // purpose  : Sets myState = -1 a private field indicating which methode is active
1830 //=======================================================================
1831 void GeometryGUI::ResetState()
1832 {  this->myState = -1 ;  return ; }
1833
1834
1835 //=======================================================================
1836 // function : EmitSignalDeactivateDialog()
1837 // purpose  : Emit a signal to deactivate the active dialog Box
1838 //=======================================================================
1839 void GeometryGUI::EmitSignalDeactivateDialog()
1840 {
1841   emit this->SignalDeactivateActiveDialog() ;
1842   return ;
1843 }
1844
1845 //=======================================================================
1846 // function : EmitSignalCloseAllDialogs()
1847 // purpose  : Emit a signal to deactivate all non modal dialogs box
1848 //=======================================================================
1849 void GeometryGUI::EmitSignalCloseAllDialogs()
1850 {
1851   emit this->SignalCloseAllDialogs() ;
1852   return ;
1853 }
1854
1855
1856 //=======================================================================
1857 // function : GetActiveDialogBox()
1858 // purpose  : 
1859 //=======================================================================
1860 QDialog* GeometryGUI::GetActiveDialogBox()
1861 {
1862   return this->myActiveDialogBox ;
1863 }
1864
1865
1866 //=======================================================================
1867 // function : SetActiveDialogBox()
1868 // purpose  : 
1869 //=======================================================================
1870 void GeometryGUI::SetActiveDialogBox(QDialog* aDlg)
1871 {
1872   this->myActiveDialogBox = (QDialog*)aDlg ;
1873   return ;
1874 }
1875
1876
1877 //=======================================================================
1878 // function : GetActiveStudy()
1879 // purpose  : 
1880 //=======================================================================
1881 QAD_Study* GeometryGUI::GetActiveStudy()
1882 {
1883   return this->myActiveStudy ;
1884 }
1885
1886
1887 //=======================================================================
1888 // function : GetActiveDesktop()
1889 // purpose  : 
1890 //=======================================================================
1891 QAD_Desktop* GeometryGUI::GetDesktop()
1892 {
1893   return this->myDesktop ;
1894 }
1895
1896
1897 //=====================================================================================
1898 // function : OnSubShapeGetAll()
1899 // purpose  : Explode a shape in all sub shapes with a SubShapeType
1900 //=====================================================================================
1901 bool GeometryGUI::OnSubShapeGetAll(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR, const int SubShapeType)
1902 {
1903   SALOMEDS::Study_var   aStudy = myActiveStudy->getStudyDocument();
1904   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR );
1905   if ( theObj->_is_nil() ) {
1906     myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
1907     return false ;
1908   }
1909
1910   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1911   SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry());
1912   SALOMEDS::GenericAttribute_var anAttr;
1913   SALOMEDS::AttributeName_var    aName;
1914   SALOMEDS::AttributeIOR_var     anIOR;
1915   SALOMEDS::AttributePixMap_var  aPixmap;
1916
1917   /* We create a sub object for each sub shape as attribute of the main object  */
1918   /* Each sub object contains list (length=1) containing its index in the main shape */
1919   GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
1920   GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
1921   GEOM::GEOM_Shape_var aResult ;
1922   
1923   try {
1924     listGeomShapes = myComponentGeom->SubShapeAll( aShape, SubShapeType );
1925     if( listGeomShapes->length() < 1 ) {
1926       myDesktop->putInfo (tr("GEOM_PRP_ABORT"));
1927       return false ;
1928     }
1929   }
1930   catch (const SALOME::SALOME_Exception& S_ex) {
1931     QtCatchCorbaException(S_ex);
1932   }
1933   
1934   /* open transaction */
1935   QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
1936   op->start();
1937   
1938   TopoDS_Shape mainTopo = ShapeReader.GetShape(myComponentGeom, aShape);
1939   TopoDS_Shape mainShape;
1940   bool main = false;
1941   while ( !main ) {
1942     if ( aShape->IsMainShape() ) {
1943       mainShape = ShapeReader.GetShape(myComponentGeom, aShape);
1944       main = true;
1945     } else
1946       aShape = myComponentGeom->GetIORFromString( aShape->MainName() );
1947   }
1948   
1949   /* Loop on each sub shape created */
1950   /* int i = 1 ; /* index for the nameType */  
1951   for( int j=0; j<listGeomShapes->length(); j++) {
1952     
1953     /* Get each sub shape extracted CORBA and OCC */
1954     aResult = listGeomShapes[j] ;    
1955     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult);
1956     
1957     if ( S.IsNull() ) {
1958       myDesktop->putInfo (tr("GEOM_PRP_ABORT"));
1959       return false;
1960     }
1961
1962 // NRI : Following lines are commented according to bugID SAL695 (see history)
1963 //      BRepCheck_Analyzer anAnalyzer(S);
1964 //      if(!anAnalyzer.IsValid()) {
1965 //        myDesktop->putInfo (tr("GEOM_PRP_ABORT"));
1966 //        MESSAGE("#### An exploded shape number "<< j << " is not valid");
1967 //        op->abort();
1968 //        return false;
1969 //      }
1970     
1971     /* Set the nameType of sub shape */
1972     char* nameG = (char *)malloc(20);
1973     Standard_CString Type;
1974     if ( GetShapeTypeString(S, Type) ) {
1975       aResult->NameType( Type );
1976       sprintf (nameG, "%s_%d", Type, GetIndex( S, mainShape, SubShapeType ) );
1977     } 
1978     else {
1979       aResult->NameType( tr("GEOM_SHAPE") );
1980       sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ );
1981     }
1982     SALOMEDS::SObject_var   SO = aStudy->FindObjectIOR( aResult->Name() );
1983
1984     bool allreadyexist = false;
1985           
1986     if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1987       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1988       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
1989       
1990       Handle(GEOM_AISShape) result = new GEOM_AISShape( S, nameG );      
1991       Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior, "GEOM");
1992       
1993       MESSAGE ( "SO->_is_nil() " << SO->_is_nil() )
1994
1995       if ( SO->_is_nil() ) {
1996         SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject( theObj );
1997         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1998         aName = SALOMEDS::AttributeName::_narrow(anAttr);
1999         aName->SetValue(nameG);
2000         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
2001         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2002         anIOR->SetValue(aResult->Name());
2003
2004         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
2005         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2006         MESSAGE( " Type " << S.ShapeType() )
2007         if ( S.ShapeType() == TopAbs_COMPOUND ) {
2008           aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
2009         } else if ( S.ShapeType() == TopAbs_COMPSOLID ) {
2010           aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
2011         } else if ( S.ShapeType() == TopAbs_SOLID ) {
2012           aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
2013         } else if ( S.ShapeType() == TopAbs_SHELL ) {
2014           aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
2015         } else if ( S.ShapeType() == TopAbs_FACE ) {
2016           aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
2017         } else if ( S.ShapeType() == TopAbs_WIRE ) {
2018           aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
2019         } else if ( S.ShapeType() == TopAbs_EDGE ) {
2020           aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
2021         } else if ( S.ShapeType() == TopAbs_VERTEX ) {
2022           aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
2023         }
2024
2025         MESSAGE ( " aPixmap->GetPixMap " << aPixmap->GetPixMap() )
2026
2027         SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
2028         aStudyBuilder->Addreference(newObj1, newObj);
2029         IO->setEntry(newObj->GetID());
2030
2031         aResult->StudyShapeId( newObj->GetID() );
2032       } else {
2033         allreadyexist = true;
2034         if ( ! SObjectExist(theObj, aResult->Name()) ) {
2035           SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
2036           aStudyBuilder->Addreference(newObj1, SO);
2037           IO->setEntry(SO->GetID());
2038           aResult->StudyShapeId( SO->GetID() );
2039         }
2040       }
2041       
2042       result->setIO( IO );
2043       result->setName( nameG );
2044       if ( !allreadyexist )
2045         ic->Display(result);
2046       
2047     } else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
2048       VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2049       
2050       int themode = myRenderInter->GetDisplayMode();
2051       vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
2052       vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
2053       
2054       Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior,"GEOM");
2055       
2056       if ( SO->_is_nil() ) {
2057         SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject( theObj );
2058         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
2059         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2060         anIOR->SetValue(aResult->Name());
2061         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
2062         aName = SALOMEDS::AttributeName::_narrow(anAttr);
2063         aName->SetValue(nameG);
2064         
2065         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
2066         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2067         if ( S.ShapeType() == TopAbs_COMPOUND ) {
2068           aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
2069         } else if ( S.ShapeType() == TopAbs_COMPSOLID ) {
2070           aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
2071         } else if ( S.ShapeType() == TopAbs_SOLID ) {
2072           aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
2073         } else if ( S.ShapeType() == TopAbs_SHELL ) {
2074           aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
2075         } else if ( S.ShapeType() == TopAbs_FACE ) {
2076           aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
2077         } else if ( S.ShapeType() == TopAbs_WIRE ) {
2078           aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
2079         } else if ( S.ShapeType() == TopAbs_EDGE ) {
2080           aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
2081         } else if ( S.ShapeType() == TopAbs_VERTEX ) {
2082           aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
2083         }
2084
2085         SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
2086         aStudyBuilder->Addreference(newObj1, newObj);
2087         IO->setEntry(newObj->GetID());
2088       } else {
2089         allreadyexist = true;
2090         if ( ! SObjectExist(theObj, aResult->Name()) ) {
2091           SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
2092           aStudyBuilder->Addreference(newObj1, SO);
2093           IO->setEntry(SO->GetID());
2094         }
2095       }
2096       
2097       if ( !allreadyexist ) {
2098         vtkActorCollection* theActors = 
2099           GEOM_AssemblyBuilder::BuildActors(S,0,themode,Standard_True);
2100         theActors->InitTraversal();
2101         vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
2102         while(!(anActor==NULL)) {
2103           GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
2104           GActor->setIO( IO );
2105           GActor->setName( nameG );
2106           theRenderer->AddActor(GActor);
2107           renWin->Render();
2108           anActor = (vtkActor*)theActors->GetNextActor();
2109         }
2110       }
2111     }
2112   }
2113
2114   /* commit transaction */
2115   op->finish();
2116   
2117   myActiveStudy->updateObjBrowser();
2118   myDesktop->putInfo (tr("GEOM_PRP_READY"));
2119   return true ;
2120 }
2121
2122
2123
2124 //=====================================================================================
2125 // function : GetIndexSubShapeSelected()
2126 // purpose  : Define a ListOfID of sub shapes selected in ShapeTopo with SubShapeType
2127 //          : Method used by Dialogs
2128 //=====================================================================================
2129 bool GeometryGUI::GetIndexSubShapeSelected( const TopoDS_Shape& ShapeTopo,
2130                                             const int SubShapeType,
2131                                             GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID,
2132                                             Standard_Integer& aLocalContextId,
2133                                             bool& myUseLocalContext )
2134 {
2135   //* Test the type of viewer */
2136   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
2137     return false;
2138   }
2139   
2140   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
2141   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
2142
2143   ic->InitSelected();
2144   int nbSelected = ic->NbSelected();
2145   ListOfID.length(nbSelected);
2146   
2147
2148   //***************** DEFINE INDEX OF EACH SELECTION *********************//
2149   int i = 0 ;
2150   ic->InitSelected(); /* to restart */
2151   while( ic->MoreSelected() ) {
2152
2153     /* Find index of sub shape into main shape */
2154     TopExp_Explorer Exp ( ShapeTopo, TopAbs_ShapeEnum(SubShapeType) );
2155     int index = 1;
2156     bool found = false ;
2157     while ( Exp.More() ) {
2158       if ( (Exp.Current()).IsSame( ic->SelectedShape()) ) {
2159         found = true ;
2160         break;
2161       }
2162       index++;
2163       Exp.Next();
2164     }
2165     if( !found ) {
2166       /* Manage local context from DialogBox */
2167       ic->CloseLocalContext(aLocalContextId) ;
2168       myUseLocalContext = false ;
2169       return false ;
2170     }
2171     ListOfID[i] = index ;
2172     i++;
2173     ic->NextSelected();
2174   }
2175     //***************** END  *********************//
2176
2177   /* Manage local context from DialogBox */
2178   ic->CloseLocalContext(aLocalContextId) ;
2179   myUseLocalContext = false ;
2180   
2181   return true ;
2182 }
2183
2184
2185 //=====================================================================================
2186 // function : OnSubShapeGetSelected()
2187 // purpose  :
2188 //=====================================================================================
2189 bool GeometryGUI::OnSubShapeGetSelected( const TopoDS_Shape& ShapeTopo,
2190                                          const char* ShapeTopoIOR,
2191                                          const int SubShapeType,
2192                                          Standard_Integer& aLocalContextId,
2193                                          bool& myUseLocalContext )
2194 {
2195   //* Test the type of viewer */
2196   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
2197     return false;
2198   }
2199
2200   SALOMEDS::Study_var   aStudy = myActiveStudy->getStudyDocument();
2201   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR );
2202   if ( theObj->_is_nil() ) {
2203     myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
2204     return false ;
2205   }
2206
2207
2208   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
2209   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
2210   
2211   if( myUseLocalContext == false ) {
2212     /* local context is from DialogBox */
2213     MESSAGE("Error : No local context opened for sub shapes method" << endl ) ;
2214     return false ;
2215   }
2216
2217   GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
2218   TopoDS_Shape mainTopo = ShapeReader.GetShape(myComponentGeom, aShape);
2219
2220   TopoDS_Shape mainShape;
2221   bool main = false;
2222   while ( !main ) {
2223     if ( aShape->IsMainShape() ) {
2224       mainShape = ShapeReader.GetShape(myComponentGeom, aShape);
2225       main = true;
2226     } else
2227       aShape = myComponentGeom->GetIORFromString( aShape->MainName() );
2228   }
2229
2230   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
2231   ic->InitSelected();
2232   int nbSelected = ic->NbSelected();
2233   ListOfID->length(nbSelected);
2234   
2235   TopoDS_Compound compound;
2236   ic->InitSelected(); /* to init again */ 
2237   BRep_Builder B;
2238   B.MakeCompound( compound );
2239
2240   int i = 0;
2241   /* We create a unique compound containing all the sub shapes selected by user as attribute of the main shape */
2242   /* the compound is homogenous by selection */
2243   while(ic->MoreSelected()) {
2244     int index = GetIndex( ic->SelectedShape(), mainShape, SubShapeType );
2245     ListOfID[i] = index ;
2246     B.Add( compound, ic->SelectedShape() );
2247     i++;
2248     ic->NextSelected();
2249   }
2250  
2251   /* Test if user has selected sub shapes */
2252   if( ListOfID->length() < 1 )
2253     return false ;
2254
2255   GEOM::GEOM_Shape_var aResult ;
2256   try {
2257     aResult = myComponentGeom->SubShape( aShape, SubShapeType, ListOfID );
2258   }
2259   catch (const SALOME::SALOME_Exception& S_ex) {
2260     QtCatchCorbaException(S_ex);
2261   }
2262
2263   /* local context from DialogBox */
2264   ic->CloseLocalContext(aLocalContextId) ;
2265   myUseLocalContext = false ;
2266
2267   char* nameG =  (char *)malloc(20);
2268   Standard_CString Type;
2269
2270   Handle(GEOM_AISShape) result; 
2271   Handle(GEOM_InteractiveObject) IO ;
2272
2273   //  if ( ! SObjectExist(theObj, aResult->Name()) ) {
2274   if ( nbSelected == 1 ) {
2275     TopExp_Explorer Exp ( compound, TopAbs_ShapeEnum(SubShapeType) );
2276     if ( Exp.More() ) {
2277       if ( GetShapeTypeString(Exp.Current(),Type) ) {
2278         aResult->NameType( Type );
2279         sprintf (nameG, "%s_%d", Type, GetIndex( Exp.Current(), mainTopo, SubShapeType ) );
2280       } else {
2281         aResult->NameType( tr("GEOM_SHAPE") );
2282         sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ );
2283       }
2284       result = new GEOM_AISShape( Exp.Current(), nameG );
2285       IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior, "GEOM");
2286     }
2287   }
2288   else {
2289     if ( GetShapeTypeString(compound,Type) ) {
2290       aResult->NameType( Type );
2291       sprintf (nameG, "%s_%d", Type, this->myNbGeom++ );
2292     } else {
2293       aResult->NameType( tr("GEOM_SHAPE") );
2294       sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ );
2295     }
2296     result = new GEOM_AISShape( compound, nameG );
2297     IO = new GEOM_InteractiveObject(aResult->Name(), Fatherior, "GEOM");
2298   }
2299   
2300   SALOMEDS::SObject_var SO = aStudy->FindObjectIOR( aResult->Name() );
2301   
2302   /* open transaction */
2303   QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
2304   op->start();
2305   
2306   SALOMEDS::StudyBuilder_var     aStudyBuilder = aStudy->NewBuilder();
2307   SALOMEDS::SObject_var          fatherSF = aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry());
2308   SALOMEDS::GenericAttribute_var anAttr;
2309   SALOMEDS::AttributeName_var    aName;
2310   SALOMEDS::AttributeIOR_var     anIOR;
2311   SALOMEDS::AttributePixMap_var  aPixmap;
2312  
2313   bool allreadyexist = false;
2314
2315   if ( SO->_is_nil() ) {
2316     SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject( theObj );
2317     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
2318     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2319     anIOR->SetValue(aResult->Name());
2320     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
2321     aName = SALOMEDS::AttributeName::_narrow(anAttr);
2322     aName->SetValue(result->getName());
2323     
2324     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
2325     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2326     if ( result->Shape().ShapeType() == TopAbs_COMPOUND ) {
2327       aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
2328     } else if ( result->Shape().ShapeType() == TopAbs_COMPSOLID ) {
2329       aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
2330     } else if ( result->Shape().ShapeType() == TopAbs_SOLID ) {
2331       aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
2332     } else if ( result->Shape().ShapeType() == TopAbs_SHELL ) {
2333       aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
2334     } else if ( result->Shape().ShapeType() == TopAbs_FACE ) {
2335       aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
2336     } else if ( result->Shape().ShapeType() == TopAbs_WIRE ) {
2337       aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
2338     } else if ( result->Shape().ShapeType() == TopAbs_EDGE ) {
2339       aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
2340     } else if ( result->Shape().ShapeType() == TopAbs_VERTEX ) {
2341       aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
2342     }
2343
2344     SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
2345     aStudyBuilder->Addreference(newObj1, newObj);
2346     
2347     IO->setEntry(newObj->GetID());
2348     aResult->StudyShapeId(newObj->GetID());
2349   } else {
2350     allreadyexist = true;
2351     if ( ! SObjectExist(theObj, aResult->Name()) ) {
2352       SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
2353       aStudyBuilder->Addreference(newObj1, SO);
2354     
2355       IO->setEntry(SO->GetID());
2356       aResult->StudyShapeId(SO->GetID());
2357     }
2358   }
2359   
2360   /* commit transaction */
2361   op->finish();
2362   
2363   result->setIO( IO );
2364   result->setName( nameG );
2365
2366   if ( !allreadyexist )
2367     ic->Display(result);
2368
2369   this->OnDisplayAll(true);
2370   myActiveStudy->updateObjBrowser();
2371   myDesktop->putInfo (tr("GEOM_PRP_READY"));
2372
2373   return true ;
2374 }
2375
2376
2377 //=====================================================================================
2378 // function : OnSuppressFaces() 
2379 // purpose  : To suppress faces from a shape
2380 //          : The result is one or more shells/faces as main shapes !
2381 //=====================================================================================
2382 bool GeometryGUI::OnSuppressFaces( const TopoDS_Shape& ShapeTopo,
2383                                    const char* ShapeTopoIOR,
2384                                    const Standard_Integer& aLocalContextId,
2385                                    bool& myUseLocalContext )
2386 {
2387   /* Test the type of viewer */
2388   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
2389     return false;
2390   }
2391   
2392   SALOMEDS::Study_var   aStudy = myActiveStudy->getStudyDocument();
2393   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR );
2394   if ( theObj->_is_nil() ) {
2395     myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
2396     return false ;
2397   }
2398   
2399   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
2400   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
2401   
2402   if( myUseLocalContext == false ) {
2403     /* local context is from DialogBox */
2404     MESSAGE("Error : No local context opened for suppress faces method" << endl ) ;
2405     return false ;
2406   }
2407   
2408   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
2409   ic->InitSelected();
2410   int nbSelected = ic->NbSelected();
2411   ListOfID->length(nbSelected);
2412
2413   /* Create a list of indices of faces to be suppressed */
2414   int i = 0;
2415   const int SubShapeType = 4 ; /* GEOM::FACE type */
2416   ic->InitSelected();          /* to repositioning at beginning */
2417   while( ic->MoreSelected() ) {
2418     int index = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType );
2419     ListOfID[i] = index ;
2420     i++;
2421     ic->NextSelected();
2422   }
2423   
2424   /* Close local context opened in DialogBox */
2425   ic->CloseLocalContext(aLocalContextId) ;
2426   myUseLocalContext = false ;
2427   
2428   /* Here is the main shape */
2429   GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( ShapeTopoIOR );  
2430   GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
2431   
2432   /* Call geom method that return a list of shells/faces as result of suppress */
2433   try {
2434     listGeomShapes = myComponentGeom->SuppressFaces( aShape, ListOfID );
2435   }
2436   catch (const SALOME::SALOME_Exception& S_ex) {
2437     QtCatchCorbaException(S_ex);
2438   }
2439   
2440   /* Test list of shells/faces */
2441   if( listGeomShapes->length() < 1 ) {
2442     return false ;
2443   }
2444
2445   /* Loop on each object created */
2446   for( int i=0; i<listGeomShapes->length(); i++ ) {
2447     
2448     GEOM::GEOM_Shape_var aShellOrFace = listGeomShapes[i] ;
2449     TopoDS_Shape S = ShapeReader.GetShape( this->myComponentGeom, aShellOrFace );
2450     
2451     if( S.IsNull() ) {
2452       return false ;
2453     }
2454     
2455     char* nameG =  (char *)malloc(20);
2456     Standard_CString Type;
2457     if ( GetShapeTypeString(S, Type) ) {
2458       aShellOrFace->NameType( Type );
2459       sprintf (nameG, "%s_%d", Type, this->myNbGeom++);
2460     }
2461     else {
2462       aShellOrFace->NameType( tr("GEOM_SHAPE") );
2463       sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), this->myNbGeom++ );
2464     }
2465     
2466     /* Display with name */
2467     if( !Display( aShellOrFace, nameG) ) {
2468       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
2469       return false ;
2470     }
2471   }
2472   
2473   myDesktop->putInfo (tr("GEOM_PRP_READY"));
2474   return true ;
2475 }
2476
2477
2478 //=====================================================================================
2479 // function : OnSuppressHole() 
2480 // purpose  : To suppress an hole on a shape 'ShapeTopo'.
2481 //          : 'ListOfIdEndFace' may be an empty list.
2482 //          : This means that hole do not traverse ShapeTopo.
2483 //          : Warning : the hole to be suppressed must be defined by one or two single closed wires !
2484 //=====================================================================================
2485 bool GeometryGUI::OnSuppressHole( const char* ShapeTopoIOR,
2486                                   const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdFace,
2487                                   const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWire,
2488                                   const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdEndFace )
2489 {
2490   /* Test the type of viewer */
2491   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
2492     return false;
2493   }
2494   
2495   try {
2496     GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );    
2497     GEOM::GEOM_Shape_var aResult = myComponentGeom->SuppressHole( aShape, ListOfIdFace, ListOfIdWire, ListOfIdEndFace ) ;
2498   
2499     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult);
2500     Standard_CString type;
2501     GetShapeTypeString(S,type);
2502     aResult->NameType( type );
2503
2504     if ( Display( aResult, "" ) )
2505       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
2506   }
2507   catch (const SALOME::SALOME_Exception& S_ex) {
2508     QtCatchCorbaException(S_ex);
2509   }
2510   return true ;
2511 }
2512
2513
2514 //=====================================================================================
2515 // function : OnSuppressHolesInFaceOrShell() 
2516 // purpose  : To suppress one or more holes on a face
2517 //          : 'ListOfIdWires' contains indices or wires/holes.
2518 //=====================================================================================
2519 bool GeometryGUI::OnSuppressHolesInFaceOrShell( const char* ShapeTopoIOR,
2520                                                 const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWires )
2521 {
2522   /* Test the type of viewer */
2523   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
2524     return false;
2525   }
2526   
2527   try {
2528     GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );    
2529     GEOM::GEOM_Shape_var aResult = myComponentGeom->SuppressHolesInFaceOrShell( aShape, ListOfIdWires ) ;
2530     
2531     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult);
2532     Standard_CString type;
2533     GetShapeTypeString(S,type);
2534     aResult->NameType( type );
2535     
2536     if ( Display( aResult, "") )
2537       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
2538   }
2539   catch (const SALOME::SALOME_Exception& S_ex) {
2540     QtCatchCorbaException(S_ex);
2541   }
2542   return true ;
2543 }
2544
2545
2546
2547 //=======================================================================
2548 // function : activeStudyChanged()
2549 // purpose  : static
2550 //=======================================================================
2551 void GeometryGUI::activeStudyChanged( QAD_Desktop* parent )
2552 {
2553   MESSAGE ("GeometryGUI::activeStudyChanged init.")
2554   /* Create or retrieve an object GeomGUI */
2555   GeometryGUI::GetOrCreateGeometryGUI(parent); 
2556   if(GeomGUI != 0) {  
2557
2558     if (GeomGUI->myState == CURRENT_SKETCH) {
2559       GeomGUI->mySketcher.Clear();
2560       GeomGUI->ResetState();
2561     }
2562
2563     QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
2564     bool ViewOCC = false;
2565     if ( GeomGUI->myDesktop->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) 
2566       ViewOCC = true;
2567
2568     Mb->setItemEnabled( 312, ViewOCC); //Sketch
2569     Mb->setItemEnabled( 309, ViewOCC); //SuppressFace
2570     Mb->setItemEnabled( 314, ViewOCC); //SuppressHole
2571     
2572     Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings
2573     Mb->setItemEnabled( 704, ViewOCC);// Isos Settings
2574
2575     GeomGUI->EraseSimulationShape() ;
2576     GeomGUI->EmitSignalCloseAllDialogs() ;
2577     GeomGUI = 0 ;
2578   }
2579
2580   //  GeomGUI->SetSettings( parent );
2581   // MESSAGE ("GeometryGUI::activeStudyChanged done.")
2582   return ;
2583 }
2584
2585
2586 //=======================================================================
2587 // function : DefineDlgPosition()
2588 // purpose  : Define x and y the default position for a dialog box
2589 //=======================================================================
2590 bool GeometryGUI::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
2591 {
2592   /* Here the position is on the bottom right corner - 10 */
2593   QAD_Desktop* PP = QAD_Application::getDesktop() ;
2594   x = abs ( PP->x() + PP->size().width()  - aDlg->size().width()  - 10 ) ;
2595   y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ;
2596   return true ;  
2597 }
2598
2599 //=======================================================================
2600 // function : OnGUIEvent() [static]
2601 // purpose  : manage all events on GUI
2602 //=======================================================================
2603 bool GeometryGUI::OnGUIEvent(int theCommandID,  QAD_Desktop* parent)
2604 {
2605   /* Create or retrieve an object GeomGUI */
2606   GeometryGUI::GetOrCreateGeometryGUI(parent);
2607
2608   SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
2609   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2610   
2611   OCCViewer_Viewer3d* v3d;
2612   Handle(AIS_InteractiveContext) ic;
2613   vtkRenderer* Renderer;
2614
2615   QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
2616
2617   bool ViewOCC = false;
2618
2619   if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
2620     v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
2621     ic = v3d->getAISContext();
2622     ViewOCC = true;    
2623     Mb->setItemEnabled( 312, ViewOCC);//Sketch
2624     Mb->setItemEnabled( 309, ViewOCC);//SuppressFace
2625     Mb->setItemEnabled( 314, ViewOCC);//SuppressHole
2626     
2627     Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings
2628     Mb->setItemEnabled( 704, ViewOCC);// Isos Settings
2629
2630   } else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
2631     Renderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
2632
2633     // OnSuppressFaces, OnSuppressHole, SETTINGS - SHADING COLOR, SETTINGS - ISOS, SETTINGS : STEP VALUE FOR SPIN BOXES, SKETCHER, ISOS - POPUP VIEWER, 
2634     Mb->setItemEnabled( 312, ViewOCC);//Sketch
2635     Mb->setItemEnabled( 309, ViewOCC);//SuppressFace
2636     Mb->setItemEnabled( 314, ViewOCC);//SuppressHole
2637     
2638     Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings
2639     Mb->setItemEnabled( 704, ViewOCC);// Isos Settings
2640   } else {
2641     return 0;
2642   }
2643
2644   if (GeomGUI->myState == CURRENT_SKETCH && theCommandID != 10000 && theCommandID != 10001 && theCommandID != 10002 && theCommandID != 10003 && theCommandID != 10004 && theCommandID != 10006 && theCommandID != 10007 && theCommandID != 10008 && theCommandID != 10010 && theCommandID != 10011 && theCommandID != 10012 && theCommandID != 10013 && theCommandID != 10014 && theCommandID != 3133 && theCommandID != 3134)
2645     return false;
2646
2647   switch (theCommandID)
2648     { 
2649     case 31: // COPY
2650       GeomGUI->OnEditCopy();
2651       break;
2652     
2653     case 33: // DELETE
2654       GeomGUI->OnEditDelete();
2655       break;
2656
2657     case 111:
2658       {
2659         GeomGUI->SetState(111);
2660         GeomGUI->Import();
2661         GeomGUI->ResetState();
2662         break;
2663       }
2664     case 112:
2665       {
2666         GeomGUI->SetState(112);
2667         GeomGUI->Import();
2668         GeomGUI->ResetState();
2669         break;
2670       }
2671     case 113: // IMPORT STEP
2672       {
2673         GeomGUI->SetState(113);
2674         GeomGUI->Import();
2675         GeomGUI->ResetState();
2676         break;
2677       }
2678
2679     case 121: // EXPORT BREP
2680       {
2681         GeomGUI->SetState(121);
2682         GeomGUI->Export();
2683         GeomGUI->ResetState();
2684         break;
2685       }
2686
2687     case 122: // EXPORT IGES
2688       {
2689         GeomGUI->SetState(122);
2690         GeomGUI->Export();
2691         GeomGUI->ResetState();
2692         break;
2693       }
2694
2695     case 123: // EXPORT STEP
2696       {
2697         GeomGUI->SetState(123);
2698         GeomGUI->Export();
2699         GeomGUI->ResetState();
2700         break;
2701       }
2702       
2703     case 303: // EXPLODE : use ic
2704       {         
2705         GeomGUI->EmitSignalDeactivateDialog() ;
2706         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2707         GeometryGUI_SubShapeDlg *aDlg = new GeometryGUI_SubShapeDlg( parent, "", Sel, ic ) ;
2708         break ;
2709       }
2710       
2711     case 304: // GEOM::EDGE
2712       {
2713         GeomGUI->EmitSignalDeactivateDialog() ;
2714         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2715         GeometryGUI_EdgeDlg *aDlg = new GeometryGUI_EdgeDlg( parent, "", Sel ) ;
2716         break ;
2717       }
2718       
2719     case 305: // GEOM::WIRE
2720       {
2721         GeomGUI->EmitSignalDeactivateDialog() ;
2722         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2723         GeometryGUI_WireDlg *aDlg = new GeometryGUI_WireDlg( parent, "", Sel ) ;
2724         break ;
2725       }
2726       
2727     case 306: // GEOM::FACE
2728       {
2729         GeomGUI->EmitSignalDeactivateDialog() ;
2730         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2731         GeometryGUI_FaceDlg *aDlg = new GeometryGUI_FaceDlg ( parent, "", Sel ) ;
2732         break ;
2733       }
2734       
2735     case 308: // GEOM::COMPOUND
2736       {
2737         GeomGUI->EmitSignalDeactivateDialog() ;
2738         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2739         GeometryGUI_CompoundDlg *aDlg = new GeometryGUI_CompoundDlg ( parent, "", Sel ) ;
2740         break ;
2741       }
2742       
2743     case 309: // SUPPRESS FACES : use ic
2744       {
2745         GeomGUI->EmitSignalDeactivateDialog() ;
2746         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2747         GeometryGUI_SuppressFacesDlg *aDlg = new GeometryGUI_SuppressFacesDlg( parent, "", Sel, ic ) ;
2748         break ;
2749       }
2750       
2751     case 314: // SUPPRESS HOLES : use ic
2752       {
2753         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
2754           GeomGUI->EmitSignalDeactivateDialog() ;
2755           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2756           GeometryGUI_SuppressHoleDlg *aDlg = new GeometryGUI_SuppressHoleDlg( parent, "", Sel, ic ) ;
2757         }
2758         else { 
2759           GeomGUI->myDesktop->putInfo( tr("GEOM_PRP_NOT_FOR_VTK_VIEWER") ) ;
2760         }
2761         break ;
2762       }
2763     case 501: // SEWING
2764       {
2765         GeomGUI->EmitSignalDeactivateDialog() ;
2766         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2767         GeometryGUI_SewingDlg *aDlg = new GeometryGUI_SewingDlg ( parent, "", Sel ) ;
2768         break ;
2769       }
2770       
2771     case 502: // ORIENTATION
2772       {
2773         GeomGUI->EmitSignalDeactivateDialog() ;
2774         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2775         GeometryGUI_OrientationDlg *aDlg = new GeometryGUI_OrientationDlg( parent, "", Sel ) ;
2776         break ;
2777       }
2778       
2779     case 601: // PROPERTIES (Length, surface, volume)
2780       {
2781         GeomGUI->EmitSignalDeactivateDialog() ;
2782         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2783         GeometryGUI_PropertiesDlg *aDlg = new GeometryGUI_PropertiesDlg( parent, "", Sel ) ;
2784         break ;
2785       }
2786       
2787     case 604: // CDG : Center of mass
2788       {
2789         GeomGUI->EmitSignalDeactivateDialog() ;
2790         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2791         GeometryGUI_CenterMassDlg *aDlg = new GeometryGUI_CenterMassDlg ( parent, "", Sel ) ;
2792         break ;
2793       }
2794       
2795     case 605: // INERTIA
2796       {
2797         GeomGUI->EmitSignalDeactivateDialog() ;
2798         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2799         GeometryGUI_InertiaDlg *aDlg = new GeometryGUI_InertiaDlg( parent, "", Sel ) ;
2800         break ;
2801       }
2802       
2803     case 607: // MAXTOLERANCE
2804       {
2805         GeomGUI->EmitSignalDeactivateDialog() ;
2806         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2807         GeometryGUI_MaxToleranceDlg *aDlg = new GeometryGUI_MaxToleranceDlg( parent, "", Sel ) ;
2808         break ;
2809       }
2810      
2811     case 608: // WHATIS
2812       {
2813         GeomGUI->EmitSignalDeactivateDialog() ;
2814         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2815         GeometryGUI_WhatisDlg *aDlg = new GeometryGUI_WhatisDlg( parent, "", Sel ) ;
2816         break ;
2817       }
2818       
2819     case 609: // CHECKSHAPE
2820      {
2821        GeomGUI->EmitSignalDeactivateDialog() ;
2822        SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2823        GeometryGUI_CheckShape *aDlg = new GeometryGUI_CheckShape( parent, "", Sel ) ;
2824        break ;
2825      }
2826      
2827     case 701: // SETTINGS - COPY
2828       {
2829         QMenuData* pp;
2830         QMenuItem* item = parent->menuBar()->findItem(701,&pp);
2831         bool check = !pp->isItemChecked(701);
2832         pp->setItemChecked(701,check);
2833         Settings_Copy = check;  
2834         QAD_CONFIG->addSetting( "Geometry:SettingsCopy", Settings_Copy );
2835         break;
2836       }
2837
2838     case 702: // SETTINGS - ADD IN STUDY
2839       {
2840         QMenuData* pp;
2841         QMenuItem* item = parent->menuBar()->findItem(702,&pp);
2842         bool check = !pp->isItemChecked(702);
2843         pp->setItemChecked(702,check);
2844         Settings_AddInStudy = check;
2845         
2846         QAD_CONFIG->addSetting( "Geometry:SettingsAddInStudy", Settings_AddInStudy );
2847         break;
2848       }
2849
2850     case 703: // SETTINGS - SHADING COLOR
2851       {
2852         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
2853           break;
2854         
2855         QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed");
2856         QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen");
2857         QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue");
2858         QColor color;
2859         if( !SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty() ) {        
2860           color = QColor (SCr.toInt(),
2861                           SCg.toInt(),
2862                           SCb.toInt());
2863         } else {
2864           Quantity_Color Default = Quantity_Color();
2865           color = QColor ( (int)Default.Red()  * 255.0,
2866                            (int)Default.Green()* 255.0,
2867                            (int)Default.Blue() * 255.0 );
2868         }
2869         
2870         QColor c = QColorDialog::getColor( color, QAD_Application::getDesktop() );
2871         if ( c.isValid() ) {
2872           GeomGUI->myShadingColor = Quantity_Color(c.red()  / 255.0,
2873                                                    c.green()/ 255.0,
2874                                                    c.blue() / 255.0,
2875                                                    Quantity_TOC_RGB);
2876           
2877           AIS_ListOfInteractive List;
2878           ic->DisplayedObjects(List);
2879           AIS_ListOfInteractive List1;
2880           ic->ObjectsInCollector(List1);
2881           List.Append(List1);
2882           
2883           AIS_ListIteratorOfListOfInteractive ite(List);
2884           while (ite.More()) {
2885             if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
2886               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
2887               aSh->SetShadingColor( GeomGUI->myShadingColor );
2888               ic->Redisplay( aSh, Standard_True, Standard_True);
2889             }
2890             ite.Next();
2891           }
2892           
2893           ic->UpdateCurrentViewer();
2894                 
2895           QAD_CONFIG->addSetting("Geometry:SettingsShadingColorRed",   c.red()   );
2896           QAD_CONFIG->addSetting("Geometry:SettingsShadingColorGreen", c.green() );
2897           QAD_CONFIG->addSetting("Geometry:SettingsShadingColorBlue",  c.blue()  );     
2898         }
2899         break;
2900       }
2901
2902      
2903     case 704: // SETTINGS - ISOS
2904       {
2905         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
2906           break;
2907
2908         QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
2909         QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
2910         if ( !IsoU.isEmpty() )
2911           ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
2912         else
2913           IsoU = "1";
2914         if ( !IsoV.isEmpty() )
2915           ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
2916         else
2917           IsoV = "1";
2918         
2919         GeometryGUI_NbIsosDlg * NbIsosDlg = new GeometryGUI_NbIsosDlg( QAD_Application::getDesktop(),
2920                                                                        tr("GEOM_MEN_ISOS"), TRUE );     
2921         int UIso = IsoU.toInt();
2922         int VIso = IsoV.toInt();
2923         
2924         NbIsosDlg->SpinBoxU->setValue(UIso) ;
2925         NbIsosDlg->SpinBoxV->setValue(VIso) ;
2926
2927         if ( NbIsosDlg->exec() ) {
2928           UIso = NbIsosDlg->SpinBoxU->text().toInt() ;
2929           VIso = NbIsosDlg->SpinBoxV->text().toInt() ;
2930           
2931           ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
2932           ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
2933           QAD_CONFIG->addSetting( "Geometry:SettingsIsoU", NbIsosDlg->SpinBoxU->text() ); /* text format */
2934           QAD_CONFIG->addSetting( "Geometry:SettingsIsoV", NbIsosDlg->SpinBoxV->text() ); /* text format */
2935         }
2936
2937         AIS_ListOfInteractive List;
2938         ic->DisplayedObjects(List);
2939         AIS_ListOfInteractive List1;
2940         ic->ObjectsInCollector(List1);
2941         List.Append(List1);
2942         
2943         AIS_ListIteratorOfListOfInteractive ite(List);
2944         ic->InitCurrent();
2945         if ( ic-> NbCurrents() )
2946           while (ite.More()) {
2947             if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
2948               
2949               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
2950               Handle (AIS_Drawer) CurDrawer;
2951               CurDrawer = ic->Current()->Attributes();
2952               CurDrawer->UIsoAspect()->SetNumber( UIso );
2953               CurDrawer->VIsoAspect()->SetNumber( VIso );
2954               ic->SetLocalAttributes(aSh, CurDrawer);
2955               ic->Redisplay(aSh);       
2956             }
2957             ite.Next();
2958           }
2959         ic->UpdateCurrentViewer();
2960         break;
2961       }
2962  
2963     case 705: // SETTINGS : STEP VALUE FOR SPIN BOXES
2964       {
2965         //NRI   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
2966         //NRI     break;
2967         
2968         QString step = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" );
2969         if( step.isEmpty() )
2970           step = "100.0" ;
2971
2972         Standard_Boolean res = false ;
2973         double dd = Parameter( res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3 ) ;
2974         if( res ) {
2975           QAD_CONFIG->addSetting( "Geometry:SettingsGeomStep",  QString("%1").arg(dd) ) ;
2976
2977           /* Emit signal to GeometryGUI_SpinBoxes */
2978           GeomGUI->SignalDefaultStepValueChanged( dd ) ;
2979         }
2980         else
2981           parent->putInfo(tr("GEOM_PRP_ABORT"));
2982
2983         break ;
2984       }
2985       
2986     case 801: // ADD IN STUDY - POPUP VIEWER
2987       {
2988         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
2989         const SALOME_ListIO& ListSelected = Sel->StoredIObjects();
2990         SALOME_ListIteratorOfListIO It( ListSelected );
2991         for ( ; It.More(); It.Next() ) {
2992           Handle(SALOME_InteractiveObject) IObject = It.Value();
2993           GeomGUI->AddInStudy(true, IObject);
2994         }
2995         /* Is set on the dialog box */
2996         QApplication::restoreOverrideCursor();
2997         break;
2998       }
2999
3000     case 901: // RENAME
3001       {
3002         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3003         SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3004         for ( ; It.More(); It.Next() ) {
3005           Handle(SALOME_InteractiveObject) IObject = It.Value();
3006
3007           SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
3008           SALOMEDS::GenericAttribute_var anAttr;
3009           SALOMEDS::AttributeName_var    aName;
3010           if ( !obj->_is_nil() ) {
3011             if (obj->FindAttribute(anAttr, "AttributeName")) {
3012               aName = SALOMEDS::AttributeName::_narrow(anAttr);
3013
3014               QString nm = QString( aName->Value() );
3015               nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), nm );
3016               if ( !nm.isEmpty() ) {
3017                 QApplication::setOverrideCursor( Qt::waitCursor );
3018                 GeomGUI->myActiveStudy->renameIObject( IObject, nm );
3019                 QApplication::restoreOverrideCursor();
3020               }
3021             }
3022           }
3023         }
3024         break;
3025       }  
3026  
3027     case 903: // DISPLAY OBJECT BROWSER
3028       {
3029         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
3030           // VTK
3031           QApplication::setOverrideCursor( Qt::waitCursor );
3032           
3033           SALOMEDS::SObject_var fatherSF = 
3034             aStudy->FindObjectID(GeomGUI->myActiveStudy->getActiveStudyFrame()->entry());
3035
3036           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3037           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3038           
3039           for(;It.More();It.Next()) {
3040             Handle(SALOME_InteractiveObject) IObject = It.Value();
3041             SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
3042
3043             VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
3044
3045             SALOMEDS::GenericAttribute_var anAttr;
3046             SALOMEDS::AttributeName_var    aName;
3047             SALOMEDS::AttributeIOR_var     anIOR;
3048          
3049             if(myRenderInter->isInViewer(IObject)) {
3050               myRenderInter->Display(IObject);
3051             }
3052             else {
3053               // Create new actor
3054               if ( !obj->_is_nil() ) {
3055                 if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
3056                   // this SObject may be GEOM module root SObject
3057                   SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
3058                   bool useSubItems = false;
3059                   while (anIter->More() && !useSubItems) {
3060                     SALOMEDS::SObject_var subobj = anIter->Value();
3061                     SALOMEDS::GenericAttribute_var aTmpAttr;
3062                     if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
3063                       anAttr = aTmpAttr;
3064                       obj = subobj;
3065                       useSubItems = true;
3066                     } else anIter->Next();
3067                   }
3068                   
3069                   while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
3070                     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3071                     GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
3072                     TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
3073
3074                     if (obj->FindAttribute(anAttr, "AttributeName")) {
3075                       aName = SALOMEDS::AttributeName::_narrow(anAttr);
3076
3077                       vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3078                       vtkActorCollection* theAllActors = theRenderer->GetActors();
3079                       theAllActors->InitTraversal();
3080                       vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
3081                       Handle(SALOME_InteractiveObject) anIObj;
3082                       // don't create new study object if it already exists
3083                       bool isDisplayed = false;
3084                       while(!(actor==NULL)) {
3085                         SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
3086                         if (Gactor!=NULL) {
3087                           if (Gactor->hasIO()) {
3088                             if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
3089                               isDisplayed = true;
3090                               anIObj = Gactor->getIO();
3091                               if (!anIObj.IsNull()) myRenderInter->Display(anIObj);
3092                             }
3093                           }
3094                         }
3095                         actor=(vtkActor*)(theAllActors->GetNextActor());
3096                       }
3097                       if (!isDisplayed) {
3098                         // open transaction
3099                         QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy );
3100                         op->start();
3101                         
3102                         SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
3103                         aStudyBuilder->Addreference(newObj1, obj);
3104                         // commit transaction
3105                         op->finish();
3106                         
3107                         vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3108                         int themode = myRenderInter->GetDisplayMode();
3109                         
3110                         vtkActorCollection* theActors = 
3111                           GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
3112                         theActors->InitTraversal();
3113                         vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
3114                         while(!(anActor==NULL)) {
3115                           GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
3116                           Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), Fatherior,"GEOM");
3117                           IO->setEntry(obj->GetID());
3118                           GActor->setIO( IO );
3119                           GActor->setName( IObject->getName() );
3120                           
3121                           theRenderer->AddActor(GActor);
3122                           renWin->Render();
3123                           anActor = (vtkActor*)theActors->GetNextActor();
3124                         }
3125                       }
3126                     }
3127                     // next item iteration
3128                     if (useSubItems) {
3129                       anIter->Next();
3130                       anAttr = SALOMEDS::GenericAttribute::_nil();
3131                       while (anIter->More() && anAttr->_is_nil()) {
3132                         SALOMEDS::SObject_var subobject = anIter->Value();
3133                         SALOMEDS::GenericAttribute_var aTmpAttribute;
3134                         if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
3135                           anAttr = aTmpAttribute;
3136                           obj = subobject;
3137                         } else anIter->Next();
3138                       }
3139                     } else anAttr = SALOMEDS::GenericAttribute::_nil();
3140                   }
3141                 }
3142               }
3143             }
3144           }
3145           GeomGUI->myActiveStudy->updateObjBrowser( true );
3146           QApplication::restoreOverrideCursor();
3147
3148         } else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
3149           QApplication::setOverrideCursor( Qt::waitCursor );
3150           
3151           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3152           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3153           for(;It.More();It.Next()) {
3154             Handle(SALOME_InteractiveObject) IObject = It.Value();
3155
3156             SALOMEDS::SObject_var fatherSF = 
3157               aStudy->FindObjectID( GeomGUI->myActiveStudy->getActiveStudyFrame()->entry());
3158             SALOMEDS::GenericAttribute_var anAttr;
3159             SALOMEDS::AttributeName_var    aName;
3160             SALOMEDS::AttributeIOR_var     anIOR;
3161
3162             if ( v3d->isInViewer( IObject, true ) ) {
3163               Standard_Boolean found;
3164               Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( IObject, found, true );
3165               if ( found ) {
3166                 ic->Display(aSh);
3167                 ic->AddOrRemoveCurrentObject(aSh, true);
3168               }
3169               
3170             } else {
3171               SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );        
3172               if ( !obj->_is_nil() ) {
3173                 if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
3174                   // this SObject may be GEOM module root SObject
3175                   SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
3176                   bool useSubItems = false;
3177                   while (anIter->More() && !useSubItems) {
3178                     SALOMEDS::SObject_var subobj = anIter->Value();
3179                     SALOMEDS::GenericAttribute_var aTmpAttr;
3180                     if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
3181                       anAttr = aTmpAttr;
3182                       obj = subobj;
3183                       useSubItems = true;
3184                     } else anIter->Next();
3185                   }
3186                   while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
3187                     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3188                     GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
3189                     TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
3190                     if (obj->FindAttribute(anAttr, "AttributeName")) {
3191                       aName = SALOMEDS::AttributeName::_narrow(anAttr);
3192                       // searchin for already displayed objects with the same shape
3193                       AIS_ListOfInteractive aDisplayed;
3194                       ic->DisplayedObjects(aDisplayed);
3195                       AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
3196                       Handle(AIS_Shape) anAISShape;
3197                       for(;anIObjects.More();anIObjects.Next()) {
3198                         anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
3199                         if (!anAISShape.IsNull()) {
3200                           if (anAISShape->Shape().IsSame(Shape)) break;
3201                           anAISShape.Nullify();
3202                         }
3203                       }
3204                       if (!anAISShape.IsNull()) {
3205                         if (!ic->IsDisplayed(anAISShape)) ic->Display(anAISShape);
3206                       } else {
3207                         if (!useSubItems) {
3208                           // open transaction
3209                           QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy );
3210                           op->start();
3211                           
3212                           SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
3213                           aStudyBuilder->Addreference(newObj1, obj);
3214                           // commit transaction
3215                           op->finish();
3216                         }
3217
3218                         Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
3219                         aSh->SetShadingColor( GeomGUI->myShadingColor );
3220                         Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(),
3221                                                                                        Fatherior,
3222                                                                                        "GEOM");
3223                         IO->setEntry(obj->GetID());
3224                         aSh->setIO( IO );
3225                         aSh->setName( aName->Value() );
3226                         ic->Display (aSh);
3227                         if (!useSubItems) ic->AddOrRemoveCurrentObject(aSh, true);
3228                       }
3229                     }
3230                     // next item iteration
3231                     if (useSubItems) {
3232                       anIter->Next();
3233                       anAttr=SALOMEDS::GenericAttribute::_nil();
3234                       while (anIter->More() && anAttr->_is_nil()) {
3235                         SALOMEDS::SObject_var subobject = anIter->Value();
3236                         SALOMEDS::GenericAttribute_var aTmpAttribute;
3237                         if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
3238                           anAttr = aTmpAttribute;
3239                           obj = subobject;
3240                         } else anIter->Next();
3241                       }
3242                     } else anAttr = SALOMEDS::GenericAttribute::_nil();
3243                   }
3244                 }
3245               }
3246             }
3247           }
3248           GeomGUI->myActiveStudy->updateObjBrowser( true );
3249           QApplication::restoreOverrideCursor();
3250         }
3251         break;
3252       }
3253       
3254     case 3011: // POINT
3255       {
3256         GeomGUI->EmitSignalDeactivateDialog() ;
3257         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3258         GeometryGUI_PointDlg *aDlg = new GeometryGUI_PointDlg( parent, "", Sel, ic ) ; 
3259         break;
3260       }
3261       
3262     case 3012:  // LINE
3263       {
3264         GeomGUI->EmitSignalDeactivateDialog() ;
3265         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3266         GeometryGUI_LineDlg *aDlg = new GeometryGUI_LineDlg( parent, "", Sel ) ;
3267         break ;
3268       }
3269       
3270     case 3013:  // CIRCLE
3271       {
3272         GeomGUI->EmitSignalDeactivateDialog() ;
3273         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3274         GeometryGUI_CircleDlg *aDlg = new GeometryGUI_CircleDlg( parent, "", Sel ) ;
3275         break ;
3276       }
3277
3278     case 3015:  // ARC
3279       {
3280         GeomGUI->EmitSignalDeactivateDialog() ;
3281         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3282         GeometryGUI_ArcDlg *aDlg = new GeometryGUI_ArcDlg( parent, "", Sel ) ;
3283         break ;
3284       }
3285       
3286     case 3016: // VECTOR
3287       { 
3288         GeomGUI->EmitSignalDeactivateDialog() ;
3289         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3290         GeometryGUI_VectorDlg *aDlg = new GeometryGUI_VectorDlg( parent, "", Sel ) ;
3291         break;
3292       }
3293       
3294     case 3017: // PLANE
3295       { 
3296         GeomGUI->EmitSignalDeactivateDialog() ;
3297         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3298         GeometryGUI_PlaneDlg *aDlg = new GeometryGUI_PlaneDlg( parent, "", Sel ) ;
3299         break;
3300       }
3301       
3302     case 3018: // WORKING PLANE
3303       { 
3304         GeomGUI->EmitSignalDeactivateDialog() ;
3305         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3306         GeometryGUI_WorkingPlaneDlg *aDlg = new GeometryGUI_WorkingPlaneDlg( parent, "", Sel ) ;
3307         break;
3308       }
3309       
3310     case 312: // SKETCHER
3311       {
3312         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
3313           break;
3314
3315         GeomGUI->EmitSignalDeactivateDialog() ;
3316
3317         ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->onViewTop(); // DCQ : 28/02/2002
3318         
3319         GeomGUI->mySketcher = Sketch( v3d->getViewer3d() );
3320         GeomGUI->SetState(CURRENT_SKETCH);
3321         
3322         QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
3323         QMenuData* pp;
3324
3325         QMenuItem* item = Mb->findItem(10010,&pp);
3326         GeomGUI->mySketcher.SetParameterVisibility(LENGTH_PARAMETER,pp->isItemChecked(10010));
3327         item = Mb->findItem(10011,&pp);
3328         GeomGUI->mySketcher.SetParameterVisibility(ANGLE_PARAMETER,pp->isItemChecked(10011));
3329         item = Mb->findItem(10012,&pp);
3330         GeomGUI->mySketcher.SetParameterVisibility(RADIUS_PARAMETER,pp->isItemChecked(10012));
3331         item = Mb->findItem(10013,&pp);
3332         GeomGUI->mySketcher.SetParameterVisibility(XVALUE_PARAMETER,pp->isItemChecked(10013));
3333         item = Mb->findItem(10014,&pp);
3334         GeomGUI->mySketcher.SetParameterVisibility(YVALUE_PARAMETER,pp->isItemChecked(10014));
3335         
3336         GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
3337         item = Mb->findItem(3133,&pp);
3338         pp->setItemChecked(3133,false);
3339         item = Mb->findItem(3134,&pp);
3340         pp->setItemChecked(3134,false);
3341         break;
3342       }
3343
3344     case 3021: // BOX
3345       { 
3346         GeomGUI->EmitSignalDeactivateDialog() ;
3347         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3348         GeometryGUI_BoxDlg *aDlg = new GeometryGUI_BoxDlg( parent, "", Sel ) ;
3349         break;
3350       }
3351
3352     case 3022: // CYLINDER
3353       { 
3354         GeomGUI->EmitSignalDeactivateDialog() ;
3355         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3356         GeometryGUI_CylinderDlg *aDlg = new GeometryGUI_CylinderDlg( parent, "", Sel ) ;        
3357         break;
3358       }
3359
3360     case 3023: // SPHERE
3361       { 
3362         GeomGUI->EmitSignalDeactivateDialog() ;
3363         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3364         GeometryGUI_SphereDlg *aDlg = new GeometryGUI_SphereDlg( parent, "", Sel ) ;
3365         break;
3366       }
3367       
3368     case 3024: // TORUS
3369       { 
3370         GeomGUI->EmitSignalDeactivateDialog() ;
3371         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3372         GeometryGUI_TorusDlg *aDlg = new GeometryGUI_TorusDlg( parent, "", Sel ) ;
3373         break;
3374       }
3375
3376     case 3025: // CONE
3377       { 
3378         GeomGUI->EmitSignalDeactivateDialog() ;
3379         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3380         GeometryGUI_ConeDlg *aDlg = new GeometryGUI_ConeDlg( parent, "", Sel ) ;
3381         break;
3382       }
3383
3384     case 3131:
3385       {
3386         break;
3387       }
3388
3389     case 3133: // sketcher
3390       { 
3391         QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
3392         QMenuData* pp;
3393         QMenuItem* item = Mb->findItem(3133,&pp);
3394         pp->setItemChecked(3133,!pp->isItemChecked(3133));
3395         if (pp->isItemChecked(3133) == true) 
3396           GeomGUI->mySketcher.SetTransitionStatus(TANGENT);
3397         else
3398           GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
3399
3400         pp->setItemChecked(3134,false);
3401         break;
3402       }
3403
3404     case 3134: // sketcher
3405       {
3406         QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
3407         QMenuData* pp;
3408         QMenuItem* item = Mb->findItem(3134,&pp);
3409         pp->setItemChecked(3134,!pp->isItemChecked(3134));
3410         if (pp->isItemChecked(3134) == true) 
3411           GeomGUI->mySketcher.SetTransitionStatus(PERPENDICULAR);
3412         else 
3413           GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
3414         
3415         pp->setItemChecked(3133,false);
3416         break;
3417       }
3418
3419     case 4011: // FUSE
3420       { 
3421         GeomGUI->EmitSignalDeactivateDialog() ;
3422         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3423         GeometryGUI_FuseDlg *aDlg = new GeometryGUI_FuseDlg( parent, "", Sel ) ;
3424         break;
3425       }
3426
3427     case 4012: // COMMON
3428       { 
3429         GeomGUI->EmitSignalDeactivateDialog() ;
3430         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3431         GeometryGUI_CommonDlg *aDlg = new GeometryGUI_CommonDlg( parent, "", Sel ) ;
3432         break;
3433       }
3434
3435     case 4013: // CUT
3436       { 
3437         GeomGUI->EmitSignalDeactivateDialog() ;
3438         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3439         GeometryGUI_CutDlg *aDlg = new GeometryGUI_CutDlg( parent, "", Sel ) ;
3440         break;
3441       }
3442
3443     case 4014: // SECTION
3444       { 
3445         GeomGUI->EmitSignalDeactivateDialog() ;
3446         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3447         GeometryGUI_SectionDlg *aDlg = new GeometryGUI_SectionDlg( parent, "", Sel ) ;
3448         break;
3449       }
3450       
3451     case 4021: // TRANSLATION
3452       { 
3453         GeomGUI->EmitSignalDeactivateDialog() ;
3454         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3455         GeometryGUI_TranslationDlg *aDlg = new GeometryGUI_TranslationDlg( parent, "", Sel ) ;
3456         break;
3457       }
3458
3459     case 4022: // ROTATION
3460       { 
3461         GeomGUI->EmitSignalDeactivateDialog() ;
3462         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3463         GeometryGUI_RotationDlg *aDlg = new GeometryGUI_RotationDlg( parent, "", Sel ) ;
3464         break;
3465       }
3466
3467    case 4030: // MULTI TRANSLATION
3468       { 
3469         GeomGUI->EmitSignalDeactivateDialog() ;
3470         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3471         GeometryGUI_MultiTranslationDlg *aDlg = new GeometryGUI_MultiTranslationDlg( parent, "", Sel ) ;
3472         break;
3473       }
3474
3475     case 4040: // MULTI ROTATION
3476       { 
3477         GeomGUI->EmitSignalDeactivateDialog() ;
3478         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3479         GeometryGUI_MultiRotationDlg *aDlg = new GeometryGUI_MultiRotationDlg( parent, "", Sel ) ;
3480         break;
3481       }
3482
3483     case 4023: // MIRROR
3484       { 
3485         GeomGUI->EmitSignalDeactivateDialog() ;
3486         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3487         GeometryGUI_MirrorDlg *aDlg = new GeometryGUI_MirrorDlg( parent, "", Sel ) ;
3488         break;
3489       }
3490       
3491     case 4024: // SCALE
3492       { 
3493         GeomGUI->EmitSignalDeactivateDialog() ;
3494         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3495         GeometryGUI_ScaleDlg *aDlg = new GeometryGUI_ScaleDlg( parent, "", Sel ) ;
3496         break;
3497       }
3498       
3499     case 4025: // PARTITION
3500       {         
3501         GeomGUI->EmitSignalDeactivateDialog() ;
3502         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3503         GeometryGUI_PartitionDlg *aDlg = new GeometryGUI_PartitionDlg( parent, "", Sel ) ;      
3504         break;
3505       }
3506
3507     case 4026: // ARCHIMEDE
3508       {         
3509         GeomGUI->EmitSignalDeactivateDialog() ;
3510         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3511         GeometryGUI_ArchimedeDlg *aDlg = new GeometryGUI_ArchimedeDlg( parent, "", Sel ) ;      
3512         break;
3513       }
3514
3515     case 4027: // FILLET
3516       {         
3517         GeomGUI->EmitSignalDeactivateDialog() ;
3518         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3519         GeometryGUI_FilletDlg *aDlg = new GeometryGUI_FilletDlg( parent, "", Sel, ic ) ;        
3520         break;
3521       }
3522
3523     case 4028: // CHAMFER
3524       {         
3525         GeomGUI->EmitSignalDeactivateDialog() ;
3526         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3527         GeometryGUI_ChamferDlg *aDlg = new GeometryGUI_ChamferDlg( parent, "", Sel, ic ) ;      
3528         break;
3529       }
3530
3531     case 4031: // PRISM
3532       { 
3533         GeomGUI->EmitSignalDeactivateDialog() ;
3534         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3535         GeometryGUI_PrismDlg *aDlg = new GeometryGUI_PrismDlg( parent, "", Sel ) ;
3536         break;
3537       }
3538
3539     case 4032: // REVOL
3540       { 
3541         GeomGUI->EmitSignalDeactivateDialog() ;
3542         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3543         GeometryGUI_RevolDlg *aDlg = new GeometryGUI_RevolDlg( parent, "", Sel ) ;
3544         break;
3545       }
3546
3547     case 4033: // FILLING
3548       { 
3549         GeomGUI->EmitSignalDeactivateDialog() ;
3550         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3551         GeometryGUI_FillingDlg *aDlg = new GeometryGUI_FillingDlg( parent, "", Sel ) ;
3552         break;
3553       }
3554
3555     case 4034: // PIPE
3556       { 
3557         GeomGUI->EmitSignalDeactivateDialog() ;
3558         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3559         GeometryGUI_PipeDlg *aDlg = new  GeometryGUI_PipeDlg(parent, "", Sel ) ;
3560         break;
3561       }
3562       
3563     case 5001: // CHECK GEOMETRY
3564       {
3565         QAD_PyEditor* PyEditor = GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getPyEditor();
3566         PyEditor->setText("from GEOM_usinggeom import *\n");
3567         PyEditor->setText(">>> ");
3568         PyEditor->handleReturn();
3569         break;
3570       }
3571
3572     case 6021: // SHADING - WIREFRAME
3573       {
3574         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3575           VTKViewer_RenderWindowInteractor* myRenderInter= 
3576             ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
3577
3578           QApplication::setOverrideCursor(waitCursor); 
3579           
3580           int themode = myRenderInter->GetDisplayMode();
3581           if( themode==0 ) {
3582             myRenderInter->SetDisplayMode(1);
3583             GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_WIREFRAME") );
3584           } else {
3585             myRenderInter->SetDisplayMode(0);
3586             GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_SHADING") );
3587           }
3588
3589           QApplication::restoreOverrideCursor();          
3590           
3591         } else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
3592           AIS_DisplayMode mode = ( AIS_DisplayMode )ic->DisplayMode();
3593           QApplication::setOverrideCursor( Qt::waitCursor );
3594           AIS_DisplayMode newmode = (mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame);
3595
3596           AIS_ListOfInteractive List;
3597           ic->DisplayedObjects(List);
3598           AIS_ListOfInteractive List1;
3599           ic->ObjectsInCollector(List1);
3600           List.Append(List1);
3601           
3602           AIS_ListIteratorOfListOfInteractive ite(List);
3603           while (ite.More()) {
3604             if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
3605               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
3606               ic->SetDisplayMode(aSh,Standard_Integer(newmode),true);
3607             }
3608             ite.Next();
3609           }
3610
3611           ic->SetDisplayMode( newmode, Standard_False);
3612           if ( newmode == 1 )
3613             GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_WIREFRAME") );
3614           else
3615             GeomGUI->GetDesktop()->menuBar()->changeItem(6021, tr("GEOM_MEN_SHADING") );
3616           
3617           QApplication::restoreOverrideCursor();
3618         }
3619         break;
3620       }
3621       
3622     case 6022: // DISPLAY ALL
3623       {
3624         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
3625           //VTK
3626           ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->DisplayAll();
3627         else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC )
3628           GeomGUI->OnDisplayAll();
3629         break;
3630       }
3631       
3632     case 6023: // DISPLAY ONLY
3633     case 8023: // DISPLAY ONLY - POPUP VIEWER
3634       {
3635         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3636           // VTK
3637           GeomGUI->OnVTKDisplayOnly();
3638         }
3639         else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
3640           GeomGUI->OnDisplayOnly();
3641         break;
3642       }
3643       
3644     case 6024: // ERASE ALL
3645       {
3646         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3647           //VTK
3648           ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->EraseAll();
3649         }
3650         else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC)  {
3651           ic->EraseAll(Standard_True, Standard_False);
3652           ic->Display(v3d->getTrihedron());
3653         }
3654
3655         //NRI   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3656         //NRI   Sel->ClearInteractiveObjects();
3657         break;
3658       }
3659
3660     case 6025 : // ERASE ONLY
3661     case 8022 : // ERASE - POPUP VIEWER
3662       {
3663         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3664         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3665           // VTK
3666           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3667           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3668           Handle(SALOME_InteractiveObject) anIObject;
3669           for(;It.More();It.Next()) {
3670             anIObject = It.Value();
3671             VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
3672             
3673             if(myRenderInter->isInViewer(anIObject)) {
3674               myRenderInter->Erase(anIObject);
3675             } else {
3676               SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() );
3677               SALOMEDS::GenericAttribute_var anAttr;
3678               SALOMEDS::AttributeIOR_var     anIOR;
3679               if ( !obj->_is_nil() ) {
3680                 if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
3681                   // this SObject may be GEOM module root SObject
3682                   SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
3683                   bool useSubItems = false;
3684                   while (anIter->More() && !useSubItems) {
3685                     SALOMEDS::SObject_var subobj = anIter->Value();
3686                     SALOMEDS::GenericAttribute_var aTmpAttr;
3687                     if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
3688                       anAttr = aTmpAttr;
3689                       obj = subobj;
3690                       useSubItems = true;
3691                     } else anIter->Next();
3692                   }
3693                   
3694                   while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
3695                     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3696                     GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
3697                     TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
3698                     if (obj->FindAttribute(anAttr, "AttributeName")) {
3699                       // searchin for already displayed objects with the same shape
3700                       vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3701                       vtkActorCollection* theAllActors = theRenderer->GetActors();
3702                       theAllActors->InitTraversal();
3703                       vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
3704                       Handle(SALOME_InteractiveObject) anIObj;
3705                       // don't create new study object if it already exists
3706                       bool isDisplayed = false;
3707                       while(!(actor==NULL)) {
3708                         SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
3709                         if (Gactor!=NULL) {
3710                           if (Gactor->hasIO()) {
3711                             if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
3712                               isDisplayed = true;
3713                               anIObj = Gactor->getIO();
3714                               if (!anIObj.IsNull()) myRenderInter->Erase(anIObj);
3715                             }
3716                           }
3717                         }
3718                         actor=(vtkActor*)(theAllActors->GetNextActor());
3719                       }
3720                     }
3721                     if (useSubItems) {
3722                       anIter->Next();
3723                       anAttr=SALOMEDS::GenericAttribute::_nil();
3724                       while (anIter->More() && anAttr->_is_nil()) {
3725                         SALOMEDS::SObject_var subobject = anIter->Value();
3726                         SALOMEDS::GenericAttribute_var aTmpAttribute;
3727                         if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
3728                           anAttr = aTmpAttribute;
3729                           obj = subobject;
3730                         } else anIter->Next();
3731                       }
3732                     } else anAttr = SALOMEDS::GenericAttribute::_nil();
3733                   }
3734                 }
3735               }
3736             }
3737           }
3738 //        SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
3739 //        for(;It.More();It.Next()) {
3740 //          Handle(SALOME_InteractiveObject) IOS = It.Value();
3741           //        GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor()->Erase(IOS);;
3742         }
3743         else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
3744           // OCC
3745           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3746           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3747           Handle(SALOME_InteractiveObject) anIObject;
3748           for(;It.More();It.Next()) {
3749             anIObject = It.Value();
3750             if ( v3d->isInViewer( anIObject, true ) ) {
3751               Standard_Boolean found;
3752               Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( anIObject, found, true );
3753               if ( found ) {
3754                 ic->Erase(aSh);
3755                 ic->AddOrRemoveCurrentObject(aSh, true);
3756               }
3757             } else {
3758               SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() );
3759               SALOMEDS::GenericAttribute_var anAttr;
3760               SALOMEDS::AttributeIOR_var     anIOR;
3761               if ( !obj->_is_nil() ) {
3762                 if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
3763                   // this SObject may be GEOM module root SObject
3764                   SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
3765                   bool useSubItems = false;
3766                   while (anIter->More() && !useSubItems) {
3767                     SALOMEDS::SObject_var subobj = anIter->Value();
3768                     SALOMEDS::GenericAttribute_var aTmpAttr;
3769                     if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
3770                       anAttr = aTmpAttr;
3771                       obj = subobj;
3772                       useSubItems = true;
3773                     } else anIter->Next();
3774                   }
3775                   
3776                   while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
3777                     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3778                     GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
3779                     TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
3780                     if (obj->FindAttribute(anAttr, "AttributeName")) {
3781                       // searchin for already displayed objects with the same shape
3782                       AIS_ListOfInteractive aDisplayed;
3783                       ic->DisplayedObjects(aDisplayed);
3784                       AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
3785                       Handle(AIS_Shape) anAISShape;
3786                       for(;anIObjects.More();anIObjects.Next()) {
3787                         anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
3788                         if (!anAISShape.IsNull()) {
3789                           if (anAISShape->Shape().IsSame(Shape)) break;
3790                           anAISShape.Nullify();
3791                         }
3792                       }
3793                       if (!anAISShape.IsNull()) {
3794                         if (ic->IsDisplayed(anAISShape)) ic->Erase(anAISShape);
3795                       }
3796                     }
3797                     if (useSubItems) {
3798                       anIter->Next();
3799                       anAttr=SALOMEDS::GenericAttribute::_nil();
3800                       while (anIter->More() && anAttr->_is_nil()) {
3801                         SALOMEDS::SObject_var subobject = anIter->Value();
3802                         SALOMEDS::GenericAttribute_var aTmpAttribute;
3803                         if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
3804                           anAttr = aTmpAttribute;
3805                           obj = subobject;
3806                         } else anIter->Next();
3807                       }
3808                     } else anAttr = SALOMEDS::GenericAttribute::_nil();
3809                   }
3810                 }
3811               }
3812             }
3813           }
3814         }
3815         Sel->ClearIObjects();
3816         break;
3817       }
3818       
3819
3820     case 6060: // BOUNDING BOX
3821       {
3822         GeomGUI->EmitSignalDeactivateDialog() ;
3823         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3824         GeometryGUI_BndBoxDlg *aDlg = new  GeometryGUI_BndBoxDlg(parent, "", Sel ) ;
3825         break ;
3826       }
3827
3828     case 6061: // MIN DISTANCE
3829       {
3830         GeomGUI->EmitSignalDeactivateDialog() ;
3831         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3832         GeometryGUI_DistanceDlg *aDlg = new GeometryGUI_DistanceDlg(parent, "", Sel ) ;
3833         break ;
3834       }
3835
3836     case 8021: // WIREFRAME-SHADING
3837       {
3838         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
3839           // VTK
3840           VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
3841           
3842           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3843           SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
3844           
3845           QApplication::setOverrideCursor( Qt::waitCursor );
3846           for(;It.More();It.Next()) {
3847             Handle(SALOME_InteractiveObject) IOS = It.Value();
3848             myRenderInter->SwitchRepresentation(IOS, false);
3849           }
3850           myRenderInter->Render();
3851           QApplication::restoreOverrideCursor();
3852         }
3853         else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
3854           QApplication::setOverrideCursor( Qt::waitCursor );
3855           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3856           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3857           for(;It.More();It.Next()) {
3858             Handle(SALOME_InteractiveObject) IObject = It.Value();
3859             Standard_Boolean found;
3860             Handle(GEOM_AISShape) Shape = GeomGUI->ConvertIOinGEOMAISShape( IObject, found, true );
3861             if (!Shape.IsNull()) {
3862               AIS_DisplayMode mode = ( AIS_DisplayMode )Shape->DisplayMode();
3863               if ( mode == -1 )
3864                 mode = ( AIS_DisplayMode )ic->DisplayMode();
3865               
3866               QApplication::setOverrideCursor( Qt::waitCursor );
3867               ic->SetDisplayMode(Shape, mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame, false);
3868             }
3869             QApplication::restoreOverrideCursor();
3870           }
3871           ic->UpdateCurrentViewer();
3872         }
3873         QApplication::restoreOverrideCursor();
3874         break;
3875       }
3876       
3877     case 8031: // COLOR - POPUP VIEWER
3878       {
3879         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
3880           // VTK
3881           VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
3882           
3883           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3884           SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
3885           
3886           Handle(SALOME_InteractiveObject) FirstIOS =  Sel->firstIObject();
3887           if(!FirstIOS.IsNull()) {
3888             
3889             QColor initcolor = myRenderInter->GetColor(FirstIOS);
3890             
3891             QColor c = QColorDialog::getColor( initcolor,
3892                                                QAD_Application::getDesktop() );
3893             
3894             if ( c.isValid() ) {
3895               QApplication::setOverrideCursor( Qt::waitCursor );
3896               for(;It.More();It.Next()) {
3897                 Handle(SALOME_InteractiveObject) IOS = It.Value();
3898                 myRenderInter->SetColor(IOS,c);
3899               }
3900             }
3901             QApplication::restoreOverrideCursor();
3902           }
3903         }
3904         else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
3905           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3906           Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
3907           Standard_Boolean found;
3908           Handle(GEOM_AISShape) Shape = GeomGUI->ConvertIOinGEOMAISShape(IO, found, true);
3909           if ( found ) {
3910             Quantity_Color CSFColor;
3911             Shape->Color( CSFColor );
3912             
3913             QColor c = QColorDialog::getColor( QColor(CSFColor.Red()  * 255.0,
3914                                                       CSFColor.Green()* 255.0, 
3915                                                       CSFColor.Blue() * 255.0 ),
3916                                                QAD_Application::getDesktop() );
3917             
3918             if ( c.isValid() ) {
3919               CSFColor = Quantity_Color ( c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB );
3920               QApplication::setOverrideCursor( Qt::waitCursor );
3921             
3922               SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3923               for(;It.More();It.Next()) {
3924                 Handle(SALOME_InteractiveObject) IObject = It.Value();
3925                 Standard_Boolean found;
3926                 Handle(GEOM_AISShape) Shape = GeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
3927                 if ( found ) {
3928                   Shape->SetColor ( CSFColor );
3929                   Shape->SetShadingColor ( CSFColor );
3930                 }
3931               }
3932             }
3933           }
3934         }
3935         QApplication::restoreOverrideCursor();
3936         break;
3937       }
3938       
3939     case 8032: // TRANSPARENCY - POPUP VIEWER
3940       {
3941         GeomGUI->EmitSignalDeactivateDialog() ;
3942         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3943         GeometryGUI_TransparencyDlg *aDlg = new GeometryGUI_TransparencyDlg( parent, "", Sel, ic ) ;
3944         break ;
3945       }
3946       
3947     case 8033: // ISOS - POPUP VIEWER
3948       {
3949         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
3950           break;
3951         else {
3952           ic->InitCurrent();
3953           if ( ic->MoreCurrent() ) {
3954             Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
3955             QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
3956             QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
3957             
3958             if ( !IsoU.isEmpty() )
3959               ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
3960             else
3961               IsoU = "1";
3962             if ( !IsoV.isEmpty() )
3963               ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
3964             else
3965               IsoV = "1";
3966             
3967             GeometryGUI_NbIsosDlg * NbIsosDlg =
3968               new GeometryGUI_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE );
3969             
3970             NbIsosDlg->SpinBoxU->setValue(IsoU.toInt());
3971             NbIsosDlg->SpinBoxV->setValue(IsoV.toInt());
3972             
3973             if ( NbIsosDlg->exec() ) {
3974               QApplication::setOverrideCursor( Qt::waitCursor );
3975               for ( ; ic->MoreCurrent (); ic->NextCurrent () ) {
3976                 Handle (AIS_Drawer) CurDrawer;
3977                 
3978                 CurDrawer = ic->Current()->Attributes();
3979                 CurDrawer->UIsoAspect()->SetNumber( NbIsosDlg->SpinBoxU->text().toInt() );
3980                 CurDrawer->VIsoAspect()->SetNumber( NbIsosDlg->SpinBoxV->text().toInt() );
3981                 
3982                 ic->SetLocalAttributes(CurObject, CurDrawer);
3983                 ic->Redisplay(CurObject);
3984               }
3985             }
3986           }
3987         }
3988         QApplication::restoreOverrideCursor();
3989         break;
3990       }
3991
3992     case 9022 : // ERASE - OBJBROSER POPUP
3993       {
3994         SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3995         if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
3996           // VTK
3997           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
3998           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3999           Handle(SALOME_InteractiveObject) anIObject;
4000           for(;It.More();It.Next()) {
4001             anIObject = It.Value();
4002           VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
4003          
4004 //        Handle(SALOME_InteractiveObject) IObject;
4005           if(myRenderInter->isInViewer(anIObject)) {
4006             myRenderInter->Erase(anIObject);
4007           } else {
4008             SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() );
4009             SALOMEDS::GenericAttribute_var anAttr;
4010             SALOMEDS::AttributeIOR_var     anIOR;
4011             if ( !obj->_is_nil() ) {
4012               if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
4013                 // this SObject may be GEOM module root SObject
4014                 SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
4015                 bool useSubItems = false;
4016                 while (anIter->More() && !useSubItems) {
4017                   SALOMEDS::SObject_var subobj = anIter->Value();
4018                   SALOMEDS::GenericAttribute_var aTmpAttr;
4019                   if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
4020                     anAttr = aTmpAttr;
4021                     obj = subobj;
4022                     useSubItems = true;
4023                   } else anIter->Next();
4024                 }
4025                 
4026                 while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
4027                   anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4028                   GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
4029                   TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
4030                   if (obj->FindAttribute(anAttr, "AttributeName")) {
4031                     // searchin for already displayed objects with the same shape
4032                     vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4033                     vtkActorCollection* theAllActors = theRenderer->GetActors();
4034                     theAllActors->InitTraversal();
4035                     vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
4036                     Handle(SALOME_InteractiveObject) anIObj;
4037                     // don't create new study object if it already exists
4038                     bool isDisplayed = false;
4039                     while(!(actor==NULL)) {
4040                       SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
4041                       if (Gactor!=NULL) {
4042                         if (Gactor->hasIO()) {
4043                           if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
4044                             isDisplayed = true;
4045                             anIObj = Gactor->getIO();
4046                             if (!anIObj.IsNull()) myRenderInter->Erase(anIObj);
4047                           }
4048                         }
4049                       }
4050                       actor=(vtkActor*)(theAllActors->GetNextActor());
4051                     }
4052                   }
4053                   if (useSubItems) {
4054                     anIter->Next();
4055                     anAttr=SALOMEDS::GenericAttribute::_nil();
4056                     while (anIter->More() && anAttr->_is_nil()) {
4057                       SALOMEDS::SObject_var subobject = anIter->Value();
4058                       SALOMEDS::GenericAttribute_var aTmpAttribute;
4059                       if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
4060                         anAttr = aTmpAttribute;
4061                         obj = subobject;
4062                       } else anIter->Next();
4063                     }
4064                   } else anAttr = SALOMEDS::GenericAttribute::_nil();
4065                 }      
4066               }
4067             }
4068           }
4069 //        SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4070 //        for(;It.More();It.Next()) {
4071 //          Handle(SALOME_InteractiveObject) IOS = It.Value();
4072 //          GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor()->Erase(IOS);;
4073         }
4074 //        SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4075 //        for(;It.More();It.Next()) {
4076 //          Handle(SALOME_InteractiveObject) IOS = It.Value();
4077 //          GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor()->Erase(IOS);;
4078 //        }
4079         }
4080         else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
4081           // OCC
4082           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
4083           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
4084           Handle(SALOME_InteractiveObject) anIObject;
4085           for(;It.More();It.Next()) {
4086             anIObject = It.Value();
4087             if ( v3d->isInViewer( anIObject, true ) ) {
4088               Standard_Boolean found;
4089               Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( anIObject, found, true );
4090               if ( found ) {
4091                 ic->Erase(aSh);
4092                 ic->AddOrRemoveCurrentObject(aSh, true);
4093               }
4094             } else {
4095               SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() );
4096               SALOMEDS::GenericAttribute_var anAttr;
4097               SALOMEDS::AttributeIOR_var     anIOR;
4098               if ( !obj->_is_nil() ) {
4099                 if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
4100                   // this SObject may be GEOM module root SObject
4101                   SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
4102                   bool useSubItems = false;
4103                   while (anIter->More() && !useSubItems) {
4104                     SALOMEDS::SObject_var subobj = anIter->Value();
4105                     SALOMEDS::GenericAttribute_var aTmpAttr;
4106                     if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
4107                       anAttr = aTmpAttr;
4108                       obj = subobj;
4109                       useSubItems = true;
4110                     } else anIter->Next();
4111                   }
4112                   
4113                   while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
4114                     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4115                     GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
4116                     TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
4117                     if (obj->FindAttribute(anAttr, "AttributeName")) {
4118                       // searchin for already displayed objects with the same shape
4119                       AIS_ListOfInteractive aDisplayed;
4120                       ic->DisplayedObjects(aDisplayed);
4121                       AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
4122                       Handle(AIS_Shape) anAISShape;
4123                       for(;anIObjects.More();anIObjects.Next()) {
4124                         anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
4125                         if (!anAISShape.IsNull()) {
4126                           if (anAISShape->Shape().IsSame(Shape)) break;
4127                           anAISShape.Nullify();
4128                         }
4129                       }
4130                       if (!anAISShape.IsNull()) {
4131                         if (ic->IsDisplayed(anAISShape)) ic->Erase(anAISShape);
4132                       }
4133                     }
4134                     if (useSubItems) {
4135                       anIter->Next();
4136                       anAttr=SALOMEDS::GenericAttribute::_nil();
4137                       while (anIter->More() && anAttr->_is_nil()) {
4138                         SALOMEDS::SObject_var subobject = anIter->Value();
4139                         SALOMEDS::GenericAttribute_var aTmpAttribute;
4140                         if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
4141                           anAttr = aTmpAttribute;
4142                           obj = subobject;
4143                         } else anIter->Next();
4144                       }
4145                     } else anAttr = SALOMEDS::GenericAttribute::_nil();
4146                   }
4147                 }
4148               }
4149             }
4150           }
4151 //        QAD_Viewer3d* v3d = GeomGUI->myActiveStudy->getActiveStudyFrame()->getViewerOCC();
4152 //        Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
4153 //        myContext->EraseSelected();
4154         }
4155
4156         Sel->ClearIObjects();
4157         break;
4158       }
4159       
4160     case 9023 : // DISPLAY ONLY - OBJBROSER POPUP
4161       {
4162         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
4163           GeomGUI->OnVTKDisplayOnly();
4164         else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC )
4165           GeomGUI->OnDisplayOnly();
4166         break;
4167       }
4168
4169     case 9024 : // OPEN - OBJBROSER POPUP
4170       {
4171           SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
4172           SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
4173           Handle(SALOME_InteractiveObject) anIObject;
4174           for(;It.More();It.Next()) {
4175             anIObject = It.Value();
4176             SALOMEDS::SObject_var obj = aStudy->FindObjectID( anIObject->getEntry() );
4177             SALOMEDS::AttributePersistentRef_var aPersist;
4178             SALOMEDS::AttributeIOR_var anIOR;
4179             if ( !obj->_is_nil() ) {
4180               // this SObject may be GEOM module root SObject
4181               SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
4182               SALOMEDS::GenericAttribute_var anAttr;
4183               bool useSubItems = false;
4184               while (anIter->More() && !useSubItems) {
4185                 SALOMEDS::SObject_var subobj = anIter->Value();
4186                 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
4187                   useSubItems = true;
4188                   obj = subobj;
4189                 }
4190                 else anIter->Next();
4191               }
4192               obj->FindAttribute(anAttr, "AttributePersistentRef");
4193
4194               while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
4195                 if (!obj->FindAttribute(anAttr, "AttributeIOR") &&
4196                     obj->FindAttribute(anAttr, "AttributePersistentRef")) {
4197                   // load
4198                   Engines::Component_var comp = GeomGUI->myDesktop->getEngine("FactoryServer","Geometry");
4199                   if (!CORBA::is_nil(comp)) {
4200                     SALOMEDS::Driver_var   driver = SALOMEDS::Driver::_narrow(comp);
4201
4202
4203                     SALOMEDS::StudyBuilder_var aStudyBuilder = GeomGUI->myActiveStudy->getStudyDocument()->NewBuilder();
4204                     aStudyBuilder->LoadWith(GeomGUI->myActiveStudy->getStudyDocument()->FindComponent("GEOM"),driver);
4205
4206                   } else {
4207                     MESSAGE("Component is null");
4208                   }
4209                 }
4210                 if (useSubItems) {
4211                   anIter->Next();
4212                   obj = anIter->Value();
4213                 } else anAttr = SALOMEDS::GenericAttribute::_nil();
4214               }
4215             }
4216           }
4217         break;
4218       }
4219       
4220     case 10000 : // SKETCH Segment
4221       {
4222         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4223           break;
4224         GeomGUI->OnSketchSegment();
4225         break;
4226       }
4227     case 10001 : // SKETCH Arc
4228       {
4229         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4230           break;
4231         GeomGUI->OnSketchArc();
4232         break;
4233       }
4234     case 10002 : // SKETCH Set Angle
4235       {
4236         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4237           break;
4238         GeomGUI->OnSketchSetAngle();
4239         break;
4240       }
4241     case 10003 : // SKETCH Set X
4242       {
4243         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4244           break;
4245         GeomGUI->OnSketchSetx();
4246         break;
4247       }
4248     case 10004 : // SKETCH Set Y
4249       {
4250         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4251           break;
4252         GeomGUI->OnSketchSety();
4253         break;
4254       }
4255     case 10006 : // SKETCH Delete
4256       {
4257         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4258           break;
4259         GeomGUI->OnSketchDelete();
4260         break;
4261       }
4262     case 10007 : // SKETCH End
4263       {
4264         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4265           break;
4266         GeomGUI->OnSketchEnd();
4267         break;
4268       }
4269     case 10008 : // SKETCH Close
4270       {
4271         if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4272           break;
4273         GeomGUI->OnSketchClose();
4274         break;
4275       }
4276     case 10010 : // SKETCH OptionsOnofflengthdimension
4277       {
4278         GeomGUI->OnSketchOptionsOnofflengthdimension();
4279         break;
4280       }
4281     case 10011 : // SKETCH OptionsOnoffangledimension
4282       {
4283         GeomGUI->OnSketchOptionsOnoffangledimension();
4284         break;
4285       }
4286     case 10012 : // SKETCH OptionsOnoffradiusdimension
4287       {
4288         GeomGUI->OnSketchOptionsOnoffradiusdimension();
4289         break;
4290       }
4291     case 10013 : // SKETCH OptionsOnoffxdimension
4292       {
4293         GeomGUI->OnSketchOptionsOnoffxdimension();
4294         break;
4295       }
4296     case 10014 : // SKETCH OptionsOnoffydimension
4297       {
4298         GeomGUI->OnSketchOptionsOnoffydimension();
4299         break;
4300       }
4301
4302     default:
4303       {
4304         parent->putInfo( tr("GEOM_PRP_COMMAND").arg(theCommandID ) );
4305         break;
4306       }
4307     }
4308   
4309   return true ;
4310 }
4311
4312 //=======================================================================
4313 // function : ConvertClickToPoint()
4314 // purpose  : Returns the point clicked in 3D view
4315 //=======================================================================
4316 gp_Pnt GeometryGUI::ConvertClickToPoint( Standard_Real x,
4317                                          Standard_Real y,
4318                                          Handle(V3d_View) aView )
4319 {
4320   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
4321   aView->Eye(XEye, YEye, ZEye);
4322
4323   aView->At(XAt, YAt, ZAt);
4324   gp_Pnt EyePoint(XEye, YEye, ZEye);
4325   gp_Pnt AtPoint(XAt, YAt, ZAt);
4326
4327   gp_Vec EyeVector(EyePoint, AtPoint);
4328   gp_Dir EyeDir(EyeVector);
4329
4330   gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
4331   Standard_Real X, Y, Z;
4332   aView->Convert(x, y, X, Y, Z);
4333   gp_Pnt ConvertedPoint(X, Y, Z);
4334
4335   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
4336   gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(),
4337                                      ConvertedPointOnPlane.Y(),
4338                                      PlaneOfTheView);
4339   return ResultPoint;
4340 }
4341
4342
4343
4344
4345 //==================================================================================
4346 // function : 0nMousePress()
4347 // purpose  : [static] manage mouse events
4348 //==================================================================================
4349 bool GeometryGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4350 {
4351   MESSAGE ( "GeometryGUI::OnMousePress")
4352   GeometryGUI::GetOrCreateGeometryGUI(parent);
4353
4354   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4355     return false;
4356
4357   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
4358   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
4359   OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort();
4360   
4361   /* Get the clicked or selected point */
4362   gp_Pnt thePoint;
4363
4364   if ( GeomGUI->myState == CURRENT_SKETCH) {
4365     GeomGUI->mySketcher.ValidateEdge();
4366     if (GeomGUI->mySketcher.GetmyEdgesNumber() == 1 ) {
4367       QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
4368       QMenuData* pp;
4369       QMenuItem* item = Mb->findItem(313,&pp);
4370       pp->setItemEnabled( 313, true);  // SKETCH CONTRAINTS
4371     }
4372   } else if( GeomGUI->myState == POINT_METHOD ) {
4373
4374     GeomGUI->EraseSimulationShape() ;
4375     GeometryGUI_PointDlg *DialogPt = (GeometryGUI_PointDlg*)(GeomGUI->myActiveDialogBox) ;
4376
4377     if ( DialogPt->UseLocalContext() ) {
4378       ic->InitSelected();
4379       if ( pe->state() == Qt::ShiftButton )
4380         v3d->getAISSelector()->shiftSelect();  /* Append selection */
4381       else
4382         v3d->getAISSelector()->select();       /* New selection    */
4383       
4384       if ( ic->MoreSelected() ) {
4385         thePoint = BRep_Tool::Pnt( TopoDS::Vertex(ic->SelectedShape()) );
4386       }
4387       else
4388         thePoint = ConvertClickToPoint(pe->x(), pe->y(), ( (OCCViewer_ViewPort3d*)vp)->getView() );
4389     } 
4390     else
4391       thePoint = ConvertClickToPoint(pe->x(), pe->y(), ( (OCCViewer_ViewPort3d*)vp)->getView() );
4392     
4393     if( DialogPt != 0 ) { 
4394       DialogPt->PointIntoCoordinates(thePoint, true) ;  /* display point */
4395     }
4396     else {
4397       // MESSAGE ("On Mouse Press : myActiveDialogBox is null"  << endl) ;
4398       GeomGUI->myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
4399     }
4400   }
4401
4402   return false ;
4403 }
4404
4405
4406 //=======================================================================
4407 // function : OnMouseMove()
4408 // purpose  : [static] manage mouse events
4409 //=======================================================================
4410 bool GeometryGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4411 {
4412   GeometryGUI::GetOrCreateGeometryGUI(parent);
4413
4414   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
4415     return false;
4416
4417   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
4418   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
4419   OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort();
4420
4421   if ( GeomGUI->myState == CURRENT_SKETCH) 
4422     GeomGUI->mySketcher.MakeCurrentEdge( pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView() );
4423   
4424    return true;
4425 }
4426
4427
4428 //================================================================================
4429 // function : SetDisplayedObjectList()
4430 // purpose  :
4431 //================================================================================
4432 void GeometryGUI::SetDisplayedObjectList()
4433 {
4434   if (myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
4435     return;
4436
4437   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
4438   ListDisplayedObject.Clear();
4439
4440   Handle (AIS_InteractiveContext) aContext = v3d->getAISContext();
4441   aContext->DisplayedObjects( ListDisplayedObject );
4442 }
4443
4444
4445
4446 //=====================================================================================
4447 // function : OnDisplayAll()
4448 // purpose  :
4449 //=====================================================================================
4450 void GeometryGUI::OnDisplayAll(bool onlyPreviousDisplayedObject)
4451 {
4452   if (myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
4453     return;
4454   
4455   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
4456   Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
4457   
4458   myContext->Display(v3d->getTrihedron());
4459
4460   if ( !onlyPreviousDisplayedObject ) {
4461     AIS_ListOfInteractive List1;
4462     myContext->ObjectsInCollector(List1);
4463     AIS_ListIteratorOfListOfInteractive ite1(List1);
4464     while (ite1.More()) {
4465       if (ite1.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
4466         Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite1.Value());
4467         if ( aSh->hasIO() ) {
4468           Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
4469           if ( v3d->isInViewer(GIO, true) ) {
4470             myContext->Display(aSh);
4471           }
4472         }
4473       }
4474       ite1.Next();
4475     }
4476   } else {
4477     AIS_ListIteratorOfListOfInteractive ite(ListDisplayedObject);
4478     while (ite.More()) {
4479       if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
4480         Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
4481         if ( aSh->hasIO() ) {
4482           Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
4483           if ( v3d->isInViewer(GIO,true) ) {
4484             myContext->Display(aSh);
4485           }
4486         }
4487       }
4488       ite.Next();
4489     }
4490   }
4491 }
4492
4493
4494
4495
4496 //=====================================================================================
4497 // function : OnVTKDisplayOnly()
4498 // purpose  :
4499 //=====================================================================================
4500 void GeometryGUI::OnVTKDisplayOnly()
4501 {
4502
4503   // Erase all not selected actors
4504   
4505   QApplication::setOverrideCursor( Qt::waitCursor );
4506
4507   vtkRenderer* aren = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4508   vtkActorCollection* theActors = aren->GetActors();
4509   theActors->InitTraversal();
4510   vtkActor *ac = theActors->GetNextActor();
4511   while(!(ac==NULL)) {
4512     if ( ac->IsA("SALOME_Actor") ) {
4513       SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
4514       if(!anActor->isHighlighted()) anActor->VisibilityOff();
4515     }
4516     ac = theActors->GetNextActor();
4517   }
4518
4519   // Display selection
4520   SALOMEDS::Study_var            aStudy = myActiveStudy->getStudyDocument();
4521   SALOMEDS::StudyBuilder_var     aStudyBuilder = aStudy->NewBuilder();
4522   SALOMEDS::SObject_var          fatherSF = aStudy->FindObjectID(GeomGUI->myActiveStudy->getActiveStudyFrame()->entry());
4523   SALOMEDS::GenericAttribute_var anAttr;
4524   SALOMEDS::AttributeName_var    aName;
4525   SALOMEDS::AttributeIOR_var     anIOR;
4526
4527   SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
4528   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
4529           
4530   for(;It.More();It.Next()) {
4531     Handle(SALOME_InteractiveObject) IObject = It.Value();
4532     SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
4533
4534     VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
4535
4536     if(myRenderInter->isInViewer(IObject)) {
4537       myRenderInter->Display(IObject);
4538     }
4539     else {
4540       // Create new actor
4541       if ( !obj->_is_nil() ) {
4542         if ( !obj->FindAttribute(anAttr, "AttributeIOR")) 
4543           break;
4544         // If selected object contains displayable subobjects, then do nothing
4545         SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
4546         SALOMEDS::GenericAttribute_var aTmpAttr;
4547         
4548         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4549         GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
4550         if (CORBA::is_nil(aShape)) continue;
4551         TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
4552
4553         if (obj->FindAttribute(anAttr, "AttributeName")) {
4554           aName = SALOMEDS::AttributeName::_narrow(anAttr);
4555           // open transaction
4556           QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy );
4557           op->start();
4558                   
4559           SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
4560           aStudyBuilder->Addreference(newObj1, obj);
4561           // commit transaction
4562           op->finish();
4563                   
4564           vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4565           int themode = myRenderInter->GetDisplayMode();
4566           vtkActorCollection* theActors = 
4567             GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
4568           theActors->InitTraversal();
4569           vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
4570           while(!(anActor==NULL)) {
4571             GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
4572             GActor->setIO( IObject );
4573             GActor->setName( IObject->getName() );
4574                     
4575             theRenderer->AddActor(GActor);
4576             vtkRenderWindow *renWin
4577               = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->GetRenderWindow();
4578             renWin->Render();
4579             anActor = (vtkActor*)theActors->GetNextActor();
4580           }
4581         }
4582       }
4583     }
4584   }
4585   GeomGUI->myActiveStudy->updateObjBrowser( true );
4586   QApplication::restoreOverrideCursor();
4587 }    
4588
4589
4590
4591 //=====================================================================================
4592 // function : OnDisplayOnly()
4593 // purpose  :
4594 //=====================================================================================
4595 void GeometryGUI::OnDisplayOnly()
4596 {
4597   if (myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
4598     return;
4599
4600   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
4601   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
4602   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
4603
4604   AIS_ListOfInteractive List;
4605   ic->DisplayedObjects(List);
4606   AIS_ListIteratorOfListOfInteractive ite(List);
4607   while (ite.More()) {
4608     if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
4609       Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
4610       if (!ic->IsSelected( aSh )) {
4611         ic->Erase( aSh, Standard_True, Standard_True );
4612       }
4613     }
4614     ite.Next();
4615   }
4616
4617   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
4618   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4619
4620   SALOME_ListIteratorOfListIO It1( Sel->StoredIObjects() );
4621   for(;It1.More();It1.Next()) {
4622     Handle(SALOME_InteractiveObject) IObject = It1.Value();
4623
4624     
4625     SALOMEDS::SObject_var fatherSF = 
4626       aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry());
4627     if ( v3d->isInViewer( IObject, true ) ) {
4628       AIS_ListOfInteractive List1;
4629       ic->ObjectsInCollector(List1);
4630       AIS_ListIteratorOfListOfInteractive ite1(List1);
4631       while (ite1.More()) {
4632         if (ite1.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
4633           Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite1.Value());
4634           if ( aSh->hasIO() ) {
4635             Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
4636             if ( IObject->isSame( GIO ) ) {
4637               ic->Display(aSh);
4638               ic->AddOrRemoveCurrentObject(aSh, true);
4639               break;
4640             }
4641           }
4642         }
4643         ite1.Next();
4644       }
4645     } else {
4646       if ( IObject->hasEntry() ) {
4647         SALOMEDS::SObject_var          obj = aStudy->FindObjectID( IObject->getEntry() );
4648         SALOMEDS::GenericAttribute_var anAttr;
4649         SALOMEDS::AttributeName_var    aName;
4650         SALOMEDS::AttributeIOR_var     anIOR;
4651         if ( !obj->_is_nil() ) {
4652           if (obj->FindAttribute(anAttr, "AttributeIOR")) {
4653             // this SObject may be GEOM module root SObject
4654
4655             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4656             GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( anIOR->Value() );
4657             if (CORBA::is_nil(aShape)) continue;
4658             TopoDS_Shape Shape = ShapeReader.GetShape(myComponentGeom, aShape);
4659             
4660             if (obj->FindAttribute(anAttr, "AttributeName")) {
4661               aName = SALOMEDS::AttributeName::_narrow(anAttr);
4662               // open transaction
4663               QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
4664               op->start();
4665               
4666               SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
4667                   aStudyBuilder->Addreference(newObj1, obj);
4668               // commit transaction
4669               op->finish();
4670             }
4671             
4672             Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
4673             Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), Fatherior,"GEOM");
4674                 
4675             IO->setEntry(obj->GetID());
4676             aSh->setIO( IO );
4677             aSh->setName( aName->Value() );
4678             ic->Display (aSh);
4679             ic->AddOrRemoveCurrentObject(aSh, true);
4680           }
4681         }  
4682       }
4683     }
4684   }
4685 }
4686
4687
4688 //===============================================================================
4689 // function : OnEditDelete()
4690 // purpose  :
4691 //===============================================================================
4692 void GeometryGUI::OnEditDelete()
4693 {
4694   if ( QAD_MessageBox::warn2 
4695        ( QAD_Application::getDesktop(),
4696          tr ("GEOM_WRN_WARNING"),
4697          tr ("GEOM_REALLY_DELETE"),
4698          tr ("GEOM_BUT_YES"), tr ("GEOM_BUT_NO"), 1, 0, 0) != 1 )
4699     return;
4700        
4701   int nbSf = myActiveStudy->getStudyFramesCount();
4702     
4703   Standard_Boolean found;
4704   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
4705   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
4706   SALOMEDS::GenericAttribute_var anAttr;
4707   SALOMEDS::AttributeIOR_var     anIOR;
4708   
4709   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4710   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
4711   for(;It.More();It.Next()) {
4712     Handle(SALOME_InteractiveObject) IObject = It.Value();
4713     if ( IObject->hasEntry() ) {
4714       SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
4715       SALOMEDS::SObject_var SO = aStudy->FindObjectID( IObject->getEntry() );
4716       
4717       /* Erase child graphical objects */
4718       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
4719       for (; it->More();it->Next()) {
4720         SALOMEDS::SObject_var CSO= it->Value();
4721         if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
4722           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4723           /* Delete child(s) shape in Client : */
4724           const TCollection_AsciiString ASCior(anIOR->Value()) ;
4725           ShapeReader.RemoveShapeFromBuffer( ASCior ) ;
4726
4727           for ( int i = 0; i < nbSf; i++ ) {
4728             QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
4729             if ( sf->getTypeView() == VIEW_OCC ) {
4730               OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
4731               Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
4732               Handle(GEOM_AISShape) Result = GeomGUI->ConvertIORinGEOMAISShape( anIOR->Value(), found );
4733               if ( found )
4734                 myContext->Erase( Result, true, false );
4735             } else if ( sf->getTypeView() == VIEW_VTK ) {
4736               //vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
4737               VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
4738               GEOM_Actor* ac = GeomGUI->ConvertIORinGEOMActor( anIOR->Value(), found );
4739               if ( found ) {
4740                 //Renderer->RemoveActor(ac);
4741                 if ( ac->hasIO() ) 
4742                   myRenderInter->Remove( ac->getIO() );
4743               }
4744             }
4745           }
4746         }
4747       }
4748       
4749       /* Erase main graphical object */
4750       for ( int i = 0; i < nbSf; i++ ) {
4751         QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
4752         if ( sf->getTypeView() == VIEW_OCC ) {
4753           OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
4754           Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
4755           Handle(GEOM_AISShape) Result = GeomGUI->ConvertIOinGEOMAISShape( IObject, found );
4756           if ( found )
4757             myContext->Erase( Result, true, false );
4758         } else if ( sf->getTypeView() == VIEW_VTK ) {
4759           VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
4760           myRenderInter->Remove( IObject );
4761         }
4762       }
4763       
4764       /* Delete main shape in Client : */
4765       if (SO->FindAttribute(anAttr, "AttributeIOR") ) {
4766         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4767         const TCollection_AsciiString ASCIor(anIOR->Value()) ;
4768         ShapeReader.RemoveShapeFromBuffer( ASCIor ) ;
4769       }
4770
4771       /* Erase objects in Study */
4772       SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
4773       if ( !obj->_is_nil() ) {
4774         QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
4775         op->start();
4776         aStudyBuilder->RemoveObject(obj);
4777         op->finish();
4778       }
4779
4780     } /* IObject->hasEntry() */
4781   }   /* more/next           */
4782
4783   /* Clear any previous selection */
4784   Sel->ClearIObjects() ; 
4785   myActiveStudy->updateObjBrowser();
4786 }
4787
4788
4789 //==============================================================================
4790 // function : OnEditCopy()
4791 // purpose  :
4792 //==============================================================================
4793 void GeometryGUI::OnEditCopy()
4794 {
4795   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4796   GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
4797
4798   const SALOME_ListIO& List = Sel->StoredIObjects();
4799
4800   GeomGUI->ConvertListOfIOInListOfIOR( List, listIOR);
4801
4802   Sel->ClearIObjects();
4803
4804   for (unsigned int ind = 0; ind < listIOR->length();ind++) {
4805     GEOM::GEOM_Shape_var aShapeInit = myComponentGeom->GetIORFromString(listIOR[ind]);
4806     try {
4807       GEOM::GEOM_Shape_var result = myComponentGeom->MakeCopy(aShapeInit) ;
4808       result->NameType( aShapeInit->NameType() );
4809       this->Display(result);
4810     }
4811     catch  (const SALOME::SALOME_Exception& S_ex) {
4812       QtCatchCorbaException(S_ex);
4813     }
4814   }
4815   
4816   myDesktop->putInfo(tr("GEOM_PRP_READY"));
4817 }
4818
4819
4820
4821 //=====================================================================================
4822 // function : OnKeyPress()
4823 // purpose  : [static]
4824 //=====================================================================================
4825 bool GeometryGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4826 {
4827   GeometryGUI::GetOrCreateGeometryGUI(parent);
4828
4829   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
4830     return false;
4831
4832   return true ;
4833 }
4834
4835
4836
4837 //=====================================================================================
4838 // function : DisplaySimulationShape() 
4839 // purpose  : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
4840 //=====================================================================================
4841 void GeometryGUI::DisplaySimulationShape(const TopoDS_Shape& S) 
4842 {
4843   if( S.IsNull() )
4844     return ;
4845         
4846   //NRI DEBUG : 14/02/2002
4847   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
4848     return ;
4849         
4850   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
4851   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
4852   
4853   try {
4854     /* erase any previous */
4855     ic->Erase( this->mySimulationShape, Standard_True, Standard_False );
4856     ic->ClearPrs( this->mySimulationShape );
4857     this->mySimulationShape = new AIS_Shape( TopoDS_Shape() ) ;
4858     this->mySimulationShape->Set( S ) ;
4859     this->mySimulationShape->SetColor(Quantity_NOC_VIOLET) ;
4860     ic->Deactivate( this->mySimulationShape );
4861     ic->Display( this->mySimulationShape, Standard_False );
4862     ic->UpdateCurrentViewer();
4863   }
4864   catch(Standard_Failure) {
4865     MESSAGE( "Exception catched in GeometryGUI::DisplaySimulationShape " ) ;
4866   } 
4867   this->mySimulationShape->UnsetColor() ;
4868   return ;
4869 }
4870
4871
4872
4873 //==================================================================================
4874 // function : EraseSimulationShape()
4875 // purpose  : Clears the display of 'mySimulationShape' a pure graphical shape
4876 //==================================================================================
4877 void GeometryGUI::EraseSimulationShape()
4878 {
4879   int count = myActiveStudy->getStudyFramesCount();
4880   for ( int i = 0; i < count; i++ ) {
4881     if (myActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC ) {
4882       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
4883       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
4884       ic->Erase( this->mySimulationShape, Standard_True, Standard_False );
4885       ic->ClearPrs( this->mySimulationShape );
4886       ic->UpdateCurrentViewer();
4887       
4888     } else if (myActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK ) { // VTK
4889     }
4890   }
4891   // MESSAGE ( " GeometryGUI::EraseSimulationShape done. " )
4892 }
4893
4894
4895
4896 //=====================================================================================
4897 // function : Import
4898 // purpose  : BRep, Iges, Step
4899 //=====================================================================================
4900 bool GeometryGUI::Import( )
4901 {
4902   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
4903   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
4904   
4905   GEOM::GEOM_Shape_var aShape;
4906   QString file;
4907   QStringList filtersList ;
4908   
4909   switch ( GeomGUI->myState )
4910     {
4911     case 111 :  // Import BREP
4912       {
4913         filtersList.append( tr("GEOM_MEN_IMPORT_BREP") );
4914         filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
4915
4916         file = QAD_FileDlg::getFileName(myDesktop,
4917                                         "",
4918                                         filtersList,
4919                                         tr("GEOM_MEN_IMPORT"),
4920                                         true);
4921         if ( !file.isEmpty() ) {
4922           QApplication::setOverrideCursor( Qt::waitCursor );
4923           try {
4924             aShape = myComponentGeom->ImportBREP( file.latin1() );
4925           }
4926           catch (const SALOME::SALOME_Exception& S_ex) {
4927             QtCatchCorbaException(S_ex);
4928           }
4929         }
4930         break;
4931       }
4932     case 112 :  // Import IGES
4933       {
4934         filtersList.append( tr("GEOM_MEN_IMPORT_IGES") ) ;
4935         filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
4936
4937         file = QAD_FileDlg::getFileName(myDesktop,
4938                                         "",
4939                                         filtersList,
4940                                         tr("GEOM_MEN_IMPORT"),
4941                                         true);
4942         if ( !file.isEmpty() ) {
4943           QApplication::setOverrideCursor( Qt::waitCursor );
4944           try {
4945             aShape = myComponentGeom->ImportIGES( file.latin1() );
4946           }
4947           catch (const SALOME::SALOME_Exception& S_ex) {
4948             QtCatchCorbaException(S_ex);
4949           }
4950         }
4951         break;
4952       }
4953     case 113 : // Import STEP
4954       {
4955         filtersList.append( tr("GEOM_MEN_IMPORT_STEP") ) ;
4956         filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
4957
4958         file = QAD_FileDlg::getFileName(myDesktop,
4959                                         "",
4960                                         filtersList,
4961                                         tr("GEOM_MEN_IMPORT"),
4962                                         true);
4963         if ( !file.isEmpty() ) {
4964           QApplication::setOverrideCursor( Qt::waitCursor );
4965           try {
4966             aShape = myComponentGeom->ImportSTEP( file.latin1() );
4967           }
4968           catch  (const SALOME::SALOME_Exception& S_ex) {
4969             QtCatchCorbaException(S_ex);
4970           }
4971         }
4972         break;
4973       }
4974     }
4975   
4976   if ( !file.isEmpty() ) {
4977     myDesktop->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) );
4978
4979     SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
4980     SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID( myActiveStudy->getActiveStudyFrame()->entry());
4981     SALOMEDS::GenericAttribute_var anAttr;
4982     SALOMEDS::AttributeName_var    aName;
4983     SALOMEDS::AttributePixMap_var  aPixmap;
4984     int aLocked = false;
4985     if (father->_is_nil()) {
4986       QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
4987       op->start();
4988       aLocked = aStudy->GetProperties()->IsLocked();
4989       if (aLocked) aStudy->GetProperties()->SetLocked(false);
4990       father = aStudyBuilder->NewComponent("GEOM");
4991       anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
4992       aName = SALOMEDS::AttributeName::_narrow(anAttr);
4993       aName->SetValue( tr("GEOM_MEN_COMPONENT") );
4994       anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
4995       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
4996       aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
4997       if (aLocked) aStudy->GetProperties()->SetLocked(true);
4998       op->finish();
4999     }
5000 //      if (aLocked) return false;
5001     aStudyBuilder->DefineComponentInstance( father, myComponentGeom );
5002     father->ComponentIOR( Fatherior );
5003
5004     QString nameShape = QAD_Tools::getFileNameFromPath(file,false) +  QString("_%1").arg(this->myNbGeom++);
5005
5006     if ( Display ( aShape, strdup(nameShape.latin1())) ) {
5007       myActiveStudy->setMessage( tr("GEOM_INF_LOADED").arg(QAD_Tools::getFileNameFromPath( file )) );
5008       myDesktop->putInfo( tr("GEOM_PRP_READY"));
5009     }
5010   }
5011   QApplication::restoreOverrideCursor();
5012   return true ;
5013 }
5014
5015
5016 //=====================================================================================
5017 // function : Export
5018 // purpose  : BRep, Iges, Step
5019 //=====================================================================================
5020 bool GeometryGUI::Export( )
5021 {
5022   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5023   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
5024
5025   GEOM::GEOM_Shape_var aShape;
5026
5027   static QString filters[] = { tr("GEOM_MEN_IMPORT_BREP"),
5028                                tr("GEOM_MEN_IMPORT_IGES"),
5029                                tr("GEOM_MEN_IMPORT_STEP") };
5030   
5031   SALOME_Selection* Sel = SALOME_Selection::Selection( this->myActiveStudy->getSelection() );
5032   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5033
5034   switch ( GeomGUI->myState )
5035     {
5036     case 121 :
5037       {
5038         for(;It.More();It.Next()) {
5039           QApplication::restoreOverrideCursor();
5040           Handle(SALOME_InteractiveObject) IObject = It.Value();
5041           Standard_Boolean found;
5042           GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5043           //      Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true);
5044           if ( found ) {
5045             QString file = QAD_FileDlg::getFileName(myDesktop, 
5046                                                     QString( IObject->getName() ) + ".brep",
5047                                                     tr("GEOM_MEN_IMPORT_BREP"),
5048                                                     tr("GEOM_MEN_EXPORT"),
5049                                                     false);
5050             if ( !file.isEmpty() && !aShape->_is_nil() ) {
5051               QApplication::setOverrideCursor( Qt::waitCursor );
5052               //      Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
5053               try {
5054                 GeomGUI->myComponentGeom->ExportBREP(strdup( file.latin1()), aShape);
5055               }  
5056               catch (const SALOME::SALOME_Exception& S_ex) {
5057                 QtCatchCorbaException(S_ex);
5058               }
5059             }
5060           }
5061         }
5062         break;
5063       }
5064     case 122 :
5065       {
5066         for(;It.More();It.Next()) {
5067           QApplication::restoreOverrideCursor();
5068           Handle(SALOME_InteractiveObject) IObject = It.Value();
5069           Standard_Boolean found;
5070           GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5071           //      Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true);
5072           if ( found ) {
5073             QString file = QAD_FileDlg::getFileName(myDesktop, 
5074                                                     QString( IObject->getName() ) + ".igs",
5075                                                     tr("GEOM_MEN_IMPORT_IGES"),
5076                                                     tr("GEOM_MEN_EXPORT"),
5077                                                     false);
5078             if ( !file.isEmpty() && !aShape->_is_nil() ) {
5079               QApplication::setOverrideCursor( Qt::waitCursor );
5080               try {
5081                 GeomGUI->myComponentGeom->ExportIGES(strdup( file.latin1()), aShape);
5082               }  
5083               catch (const SALOME::SALOME_Exception& S_ex) {
5084                 QtCatchCorbaException(S_ex);
5085               }
5086 //            //VRV: OCC 4.0 migration
5087 //            IGESControl_Controller::Init();
5088 //            IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
5089 //                                       Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
5090 //            //VRV: OCC 4.0 migration
5091
5092 //            ICW.AddShape (Shape->Shape());
5093 //            ICW.ComputeModel();
5094 //            Standard_Boolean result = ICW.Write( strdup(file.latin1()) );
5095             }
5096           }
5097         }
5098         break;
5099       }
5100
5101     case 123 :
5102       {
5103 //      bool test = false ;
5104 //      IFSelect_ReturnStatus status ;
5105 //      //VRV: OCC 4.0 migration
5106 //      STEPControl_Writer aWriter;
5107 //      //VRV: OCC 4.0 migration
5108         QString file;
5109
5110         for( ; It.More(); It.Next() ) {
5111 //        GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5112           QApplication::restoreOverrideCursor();
5113           Handle(SALOME_InteractiveObject) IObject = It.Value();
5114           Standard_Boolean found;
5115           GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5116           //      Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true);
5117           if ( found ) {
5118             file = QAD_FileDlg::getFileName(myDesktop, 
5119                                             QString( IObject->getName() ) + ".stp",
5120                                             tr("GEOM_MEN_IMPORT_STEP"),
5121                                             tr("GEOM_MEN_EXPORT"),
5122                                             false);
5123             if ( !file.isEmpty() && !aShape->_is_nil() ) {
5124
5125               QApplication::setOverrideCursor( Qt::waitCursor ) ;       
5126               try {   
5127                 GeomGUI->myComponentGeom->ExportSTEP(strdup( file.latin1()), aShape);   
5128               }  
5129               catch (const SALOME::SALOME_Exception& S_ex) {
5130                 QtCatchCorbaException(S_ex);
5131               }
5132 //            //VRV: OCC 4.0 migration
5133 //            status = aWriter.Transfer( Shape->Shape(), STEPControl_ManifoldSolidBrep ) ;
5134 //            //VRV: OCC 4.0 migration
5135 //            test = true ;
5136 //            if ( status != IFSelect_RetDone ) {
5137 //              QApplication::restoreOverrideCursor() ;
5138 //              return false ;
5139 //            }
5140             }
5141           }
5142         }
5143 //      if(test) {
5144 //        status = aWriter.Write( strdup(file.latin1()) ) ;
5145 //        QApplication::restoreOverrideCursor() ;
5146 //        return status ;
5147 //      }
5148         break;
5149       }
5150
5151     }
5152   QApplication::restoreOverrideCursor() ;
5153 }
5154
5155
5156 //=====================================================================================
5157 // function : Display()
5158 // purpose  : Displays a CORBA shape
5159 //=====================================================================================
5160 bool GeometryGUI::Display( GEOM::GEOM_Shape_ptr aShape, 
5161                            Standard_CString name)
5162 {
5163   // MESSAGE ( "GeometryGUI::Display init ") 
5164   Handle(GEOM_InteractiveObject) IO;
5165   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5166   Sel->ClearIObjects();
5167
5168   if( aShape->_is_nil() ) {
5169     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(),
5170                             tr ("GEOM_WRN_WARNING"),
5171                             tr ("GEOM_PRP_ABORT"),
5172                             tr ("GEOM_BUT_OK") );
5173     return false ;
5174   }
5175   
5176   TopoDS_Shape shape = ShapeReader.GetShape(myComponentGeom, aShape);
5177
5178   if ( shape.IsNull() )
5179     return false;
5180
5181   SALOMEDS::Study_var            aStudy = myActiveStudy->getStudyDocument();
5182   SALOMEDS::StudyBuilder_var     aStudyBuilder = aStudy->NewBuilder();
5183   SALOMEDS::GenericAttribute_var anAttr;
5184   SALOMEDS::AttributeName_var    aName;
5185   SALOMEDS::AttributePixMap_var    aPixmap;
5186
5187   SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
5188   int aLocked = false;
5189   if (father->_is_nil()) {
5190     QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5191     op->start();
5192     aLocked = aStudy->GetProperties()->IsLocked();
5193     if (aLocked) aStudy->GetProperties()->SetLocked(false);
5194     father = aStudyBuilder->NewComponent("GEOM");
5195     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
5196     aName = SALOMEDS::AttributeName::_narrow(anAttr);
5197     aName->SetValue( tr("GEOM_MEN_COMPONENT") );
5198     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
5199     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
5200     aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
5201     myActiveStudy->updateObjBrowser();
5202     if (aLocked) aStudy->GetProperties()->SetLocked(true);
5203     op->finish();
5204   }
5205 //    if (aLocked) return false;
5206
5207   aStudyBuilder->DefineComponentInstance( father, myComponentGeom );
5208   father->ComponentIOR( Fatherior );
5209
5210   TCollection_AsciiString nameG("");
5211   Standard_CString Type;
5212   if ( TCollection_AsciiString(name).IsEqual(Standard_CString("")) ) {
5213     if ( TCollection_AsciiString(aShape->NameType()).IsEqual(Standard_CString("")) ) {
5214       Standard_CString type;
5215       GetShapeTypeString(shape,type);
5216       aShape->NameType( type );
5217       nameG += TCollection_AsciiString( type ) + TCollection_AsciiString("_") + 
5218         TCollection_AsciiString( GeomGUI->myNbGeom++ ) + TCollection_AsciiString("\0");
5219     } else
5220       nameG += TCollection_AsciiString( aShape->NameType()) + TCollection_AsciiString("_") + 
5221         TCollection_AsciiString( GeomGUI->myNbGeom++ ) + TCollection_AsciiString("\0");
5222   } else 
5223     nameG = TCollection_AsciiString(name);
5224   
5225   // VTK
5226   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5227     VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5228     
5229     vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5230     int themode = myRenderInter->GetDisplayMode();
5231
5232     vtkActorCollection* theActors = 
5233       GEOM_AssemblyBuilder::BuildActors(shape,0,themode,Standard_True);
5234     theActors->InitTraversal();
5235     vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
5236
5237     IO = new GEOM_InteractiveObject(aShape->Name(),
5238                                     Fatherior,
5239                                     "GEOM");
5240     while(!(anActor==NULL)) {
5241       GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
5242       GActor->setIO( IO );
5243       GActor->setName( nameG.ToCString() );
5244       
5245       theRenderer->AddActor(GActor);
5246       anActor = (vtkActor*)theActors->GetNextActor();
5247     }
5248   } 
5249   // OCC
5250   else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5251     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
5252     Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5253     Handle(GEOM_AISShape) theResult = new GEOM_AISShape( shape, nameG.ToCString() );
5254     theResult->SetShadingColor( myShadingColor );
5255     IO = new GEOM_InteractiveObject(aShape->Name(),
5256                                     Fatherior,
5257                                     "GEOM");
5258     theResult->setIO( IO );
5259     theResult->setName( nameG.ToCString() );
5260     
5261     /* Precaution : close any local context to permit the display */
5262     if ( ic->HasOpenedContext() ) {
5263       ic->CloseAllContexts();
5264     }
5265     
5266 //     if(isInfinite)
5267 //       theResult->SetInfiniteState() ;
5268     
5269     ic->Display(theResult);
5270   }
5271
5272   Sel->AddIObject( IO, false );
5273   myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5274   if ( Settings_AddInStudy )
5275     GeomGUI->AddInStudy( false, IO );
5276   
5277   return true;
5278 }
5279
5280
5281 //=====================================================================================
5282 // function : AddInStudy() 
5283 // purpose  : anIOShape or a selected shape
5284 //=====================================================================================
5285 bool GeometryGUI::AddInStudy( bool selection,
5286                               const Handle(SALOME_InteractiveObject)& anIO)
5287 {
5288   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5289   if ( !( !Settings_AddInStudy || selection ) ) {
5290     Sel->ClearIObjects();
5291   }
5292
5293   SALOMEDS::Study_var               aStudy = myActiveStudy->getStudyDocument();
5294   SALOMEDS::StudyBuilder_var        aStudyBuilder = aStudy->NewBuilder();
5295   SALOMEDS::GenericAttribute_var    anAttr;
5296   SALOMEDS::AttributeName_var       aName;
5297   SALOMEDS::AttributePixMap_var     aPixmap;
5298   SALOMEDS::AttributeIOR_var        anIOR;
5299   SALOMEDS::AttributeSelectable_var aSelAttr;
5300   
5301   SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
5302   int aLocked = false;
5303   if (father->_is_nil()) {
5304     QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5305     op->start();
5306     aLocked = aStudy->GetProperties()->IsLocked();
5307     if (aLocked) aStudy->GetProperties()->SetLocked(false);
5308     father = aStudyBuilder->NewComponent("GEOM");
5309     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
5310     aName = SALOMEDS::AttributeName::_narrow(anAttr);
5311     aName->SetValue( tr("GEOM_MEN_COMPONENT") );
5312     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
5313     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
5314     aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
5315     if (aLocked) aStudy->GetProperties()->SetLocked(true);
5316     op->finish();
5317   }
5318 //    if (aLocked) return false;
5319
5320   aStudyBuilder->DefineComponentInstance( father, myComponentGeom );
5321   father->ComponentIOR( Fatherior );
5322   
5323   SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry());
5324   
5325   Handle(GEOM_AISShape) GAISShape;
5326   GEOM_Actor* GActor;
5327   Handle(GEOM_InteractiveObject) GIO;
5328   bool found = false;
5329
5330   // VTK
5331   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5332     vtkRenderer *Renderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5333
5334     vtkActorCollection* theActors = Renderer->GetActors();
5335     theActors->InitTraversal();
5336     vtkActor *ac = theActors->GetNextActor();
5337     while(!(ac==NULL)) {
5338       if ( ac->IsA("GEOM_Actor") ) {
5339         GEOM_Actor* anActor = GEOM_Actor::SafeDownCast( ac );
5340         if ( anActor->hasIO() ) {
5341           Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5342           if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
5343             GIO = Handle(GEOM_InteractiveObject)::DownCast( IO );
5344             if ( anIO->isSame( GIO ) ) {
5345               found = true;
5346               GActor = anActor;
5347               break;
5348             }
5349           }
5350         }
5351       }
5352       ac = theActors->GetNextActor();
5353     }
5354     
5355     if ( !found )
5356       return false;
5357   }
5358   // OCC
5359   else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC )  {
5360     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
5361     Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5362     
5363     AIS_ListOfInteractive List;
5364     ic->DisplayedObjects(List);
5365     AIS_ListIteratorOfListOfInteractive ite(List);
5366     while (ite.More()) {
5367       if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
5368         Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
5369         if ( aSh->hasIO() ) {
5370           Handle(SALOME_InteractiveObject) IO = aSh->getIO();
5371           if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
5372             GIO = Handle(GEOM_InteractiveObject)::DownCast( IO );
5373             if ( anIO->isSame( GIO ) ) {
5374               found = true;
5375               GAISShape = aSh;
5376               break;
5377             }
5378           }
5379         }
5380       }
5381       ite.Next();
5382     }
5383
5384     if ( !found )
5385       return false;
5386   }
5387
5388   if ( !Settings_AddInStudy || selection ) {
5389     QString Name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), anIO->getName() );
5390     if ( !Name.isEmpty() ) {
5391       // VTK
5392       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5393         GActor->setName( strdup(Name.latin1()) );
5394       }
5395       // OCC
5396       else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5397         GAISShape->setName( strdup(Name.latin1()) );
5398       }
5399     } else {
5400       return false;
5401     }
5402   }
5403
5404   // open transaction
5405   QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5406   op->start();
5407
5408   SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
5409
5410   GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( GIO->getIOR() );
5411
5412   /* For the shape inserted into the study we set its field 'studyshapeid'    */
5413   /* so the shape will contain its corresponding entry in the study Ocaf doc. */
5414   aShape->StudyShapeId(newObj->GetID()) ;
5415
5416   GIO->setEntry(newObj->GetID());
5417
5418   anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
5419   anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5420   anIOR->SetValue(aShape->Name());
5421
5422   anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
5423   aName = SALOMEDS::AttributeName::_narrow(anAttr);
5424
5425   anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
5426   aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
5427   if ( aShape->ShapeType() == GEOM::COMPOUND ) {
5428     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
5429   } else if ( aShape->ShapeType() == GEOM::COMPSOLID ) {
5430     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
5431   } else if ( aShape->ShapeType() == GEOM::SOLID ) {
5432     aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
5433   } else if ( aShape->ShapeType() == GEOM::SHELL ) {
5434     aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
5435   } else if ( aShape->ShapeType() == GEOM::FACE ) {
5436     aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
5437   } else if ( aShape->ShapeType() == GEOM::WIRE ) {
5438     aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
5439   } else if ( aShape->ShapeType() == GEOM::EDGE ) {
5440     aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
5441   } else if ( aShape->ShapeType() == GEOM::VERTEX ) {
5442     aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
5443   }
5444
5445   // VTK
5446   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5447     GActor->setIO( GIO );
5448     aName->SetValue(GActor->getName());
5449   }
5450   // OCC
5451   else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5452     GAISShape->setIO( GIO );
5453     aName->SetValue(GAISShape->getName());
5454   }
5455
5456   SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
5457   aStudyBuilder->Addreference(newObj1,newObj);
5458
5459   GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
5460   listIOR = myComponentGeom->GetReferencedObjects(aShape);
5461
5462   if (listIOR->length()>0) {
5463     SALOMEDS::SObject_var Arguments = aStudyBuilder->NewObject(newObj);
5464     anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeName");
5465     aName = SALOMEDS::AttributeName::_narrow(anAttr);
5466     aName->SetValue(tr("GEOM_ARGUMENTS"));
5467     anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeSelectable");
5468     aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
5469     aSelAttr->SetSelectable(false);
5470
5471     bool ObjectReferenced = false;
5472     for (unsigned int ind = 0; ind < listIOR->length();ind++) {
5473       SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(listIOR[ind]);
5474
5475       if ( !theObj->_is_nil() ) {
5476         SALOMEDS::SObject_var RefObject = aStudyBuilder->NewObject(Arguments);
5477         aStudyBuilder->Addreference(RefObject, theObj);
5478         ObjectReferenced = true;
5479       }
5480     }
5481
5482     if ( !ObjectReferenced )
5483       aStudyBuilder->RemoveObject(Arguments);
5484   }
5485
5486   op->finish();
5487
5488
5489   if ( !Settings_AddInStudy || selection ) {
5490     myActiveStudy->updateObjBrowser();
5491   } else {
5492     myActiveStudy->updateObjBrowser(false);
5493     Sel->AddIObject( GIO );
5494   }
5495
5496   // MESSAGE ( " highlihght done" )
5497   return true;
5498  
5499 }
5500
5501
5502 //=====================================================================================
5503 // function : GetShapeFromIOR()
5504 // purpose  : exist also as static method !
5505 //=====================================================================================
5506 TopoDS_Shape GeometryGUI::GetShapeFromIOR( QString IOR )
5507 {
5508   TopoDS_Shape result;
5509   if( IOR.stripWhiteSpace().isEmpty() )
5510     return result;
5511   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
5512   CORBA::ORB_var& _orb = init.orb() ;
5513   CORBA::Object_var obj = _orb->string_to_object( (char*)(IOR.latin1()) );
5514   if ( CORBA::is_nil( obj ) )
5515     return result;
5516   GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( IOR );
5517   if (!aShape->_is_nil()) {
5518     result = ShapeReader.GetShape( myComponentGeom, aShape );
5519   }
5520   return result;
5521 }
5522
5523
5524 //=====================================================================================
5525 // function : SetSettings()
5526 // purpose  : [static]
5527 //=====================================================================================
5528 bool GeometryGUI::SetSettings( QAD_Desktop* parent )
5529 {
5530   /* Create or retrieve an object GeomGUI */
5531   GeometryGUI::GetOrCreateGeometryGUI(parent);
5532
5533   //DCQ  parent->menuBar()->setItemEnabled( 504, false);  // CORRECTING
5534   //DCQ  parent->menuBar()->setItemEnabled( 6062, false); // RADIUS
5535   //VSR  parent->menuBar()->setItemEnabled( 701, false);  // AUTOMATIC COPY
5536   parent->menuBar()->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
5537   parent->menuBar()->setItemEnabled( 3131, false); // SKETCH SET PLAN
5538
5539   /* Shading Color */
5540   QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed");
5541   QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen");
5542   QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue");
5543   if( !SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty() )   
5544     GeomGUI->myShadingColor = Quantity_Color ( SCr.toInt()/255., SCg.toInt()/255., SCb.toInt()/255.,
5545                                                Quantity_TOC_RGB );
5546
5547   /* Wireframe or Shading */
5548   int DisplayMode = 0;
5549   if ( parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5550     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
5551     Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
5552     DisplayMode = ic->DisplayMode();
5553   } else if ( parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5554     VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5555     DisplayMode = myRenderInter->GetDisplayMode();
5556   }
5557
5558   if ( DisplayMode == 1 )
5559     parent->menuBar()->changeItem(6021, tr("GEOM_MEN_WIREFRAME") );
5560   else
5561     parent->menuBar()->changeItem(6021, tr("GEOM_MEN_SHADING") );
5562
5563   /* Copy */
5564 //    QString Copy = QAD_CONFIG->getSetting("Geometry:SettingsCopy");
5565 //    if ( !Copy.isEmpty() ) {
5566 //      Settings_Copy = Copy.toInt();
5567 //      QMenuData* pp;
5568 //      parent->menuBar()->findItem(701,&pp);
5569 //      pp->setItemChecked(701, Settings_Copy);
5570 //    }
5571  QMenuData* pp;
5572  if ( parent->menuBar()->findItem(701,&pp) )
5573    pp->removeItem(701);
5574
5575   /* Add in Study */
5576   QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
5577   if ( !AddInStudy.isEmpty() )
5578     Settings_AddInStudy  = AddInStudy.toInt();
5579   else
5580     Settings_AddInStudy = 1;
5581   parent->menuBar()->findItem(702,&pp);
5582   pp->setItemChecked(702, Settings_AddInStudy);
5583
5584   /* step value */
5585   QString S = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" );
5586   if( S.isEmpty() )
5587     QAD_CONFIG->addSetting( "Geometry:SettingsGeomStep", "100" );
5588   
5589   /* isos */
5590   QAD_Study* ActiveStudy = parent->getActiveStudy();
5591   int count = ActiveStudy->getStudyFramesCount();
5592
5593   bool ViewOCC = false;
5594   for ( int i = 0; i < count; i++ ) {
5595     if ( ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC ) {
5596       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
5597       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5598       
5599       QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
5600       QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
5601       if ( !IsoU.isEmpty() )
5602         ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
5603       if ( !IsoV.isEmpty() )
5604         ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
5605
5606       ViewOCC = true;
5607     }
5608   }
5609
5610   QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
5611
5612   Mb->setItemEnabled( 312, ViewOCC); //Sketch
5613   Mb->setItemEnabled( 309, ViewOCC); //SuppressFace
5614   Mb->setItemEnabled( 314, ViewOCC); //SuppressHole
5615   
5616   Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings
5617   Mb->setItemEnabled( 704, ViewOCC);// Isos Settings
5618
5619   return true;
5620 }
5621
5622
5623 //=====================================================================================
5624 // function : DefinePopup()
5625 // purpose  : [static]
5626 //=====================================================================================
5627 void GeometryGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
5628 {
5629   /* Create or retrieve an object GeomGUI */
5630   GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
5631   SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
5632
5633   theObject = "";
5634   if ( Sel->IObjectCount() == 1 ) 
5635     {
5636       Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
5637       if (IO->hasEntry())
5638         {
5639           SALOMEDS::SObject_var sobj = GeomGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
5640           if (!sobj->_is_nil()) 
5641             {
5642               SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
5643               if (strcmp(scomp->GetID(), IO->getEntry()) == 0) 
5644                 { 
5645                   // component is selected
5646                   theObject = "Component";
5647                 }
5648             }
5649         }
5650     }
5651
5652   if ( ( theParent.compare("Viewer")==0 ) ) 
5653     {
5654       if ( GeomGUI->myState == CURRENT_SKETCH ) 
5655         theContext = "Sketch";
5656       else 
5657         {
5658           if ( Sel->IObjectCount() > 0 )
5659             theContext = "";
5660           else
5661             theContext = "NothingSelected";
5662         }
5663     } 
5664   else 
5665     theContext = "";
5666   
5667 }
5668
5669 //=====================================================================================
5670 // function : CustomPopup()
5671 // purpose  : [static]
5672 //=====================================================================================
5673 bool GeometryGUI::CustomPopup( QAD_Desktop* parent,
5674                                QPopupMenu* popup,
5675                                const QString& theContext,
5676                                const QString& theParent,
5677                                const QString& theObject )
5678 {
5679   /* Create or retrieve an object GeomGUI */
5680   GeometryGUI::GetOrCreateGeometryGUI(parent);
5681   
5682   /* Deactivate any non modal dialog box to get the neutral point */
5683   GeomGUI->EmitSignalDeactivateDialog() ;
5684   
5685   SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
5686   int nbSel = Sel->IObjectCount();
5687   
5688   if ( (nbSel == 0) && ( theContext.compare("Sketch")!=0 ) )
5689     return false;
5690   
5691     
5692   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
5693     {
5694       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->
5695                                  getRightFrame()->getViewFrame())->getViewer();
5696       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5697       if ( theParent.compare("Viewer")==0 )
5698         {
5699           if ( theContext.compare("Sketch")==0 )
5700             {
5701               SketchStatus myCS = GeomGUI->mySketcher.GetCurrentStatus();
5702               popup->setCheckable(TRUE);
5703               if (myCS==SEGMENT) 
5704                 {
5705                   popup->setItemChecked(10000,true);
5706                   popup->setItemChecked(10001,false);
5707                 }
5708               else if (myCS==ARC_CHORD)
5709                 {
5710                   popup->setItemChecked(10000,false);
5711                   popup->setItemChecked(10001,true);
5712                 }
5713               
5714               return true;
5715             }
5716           else
5717             if (theObject.compare("Component") == 0)
5718               {
5719                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
5720                 return true;
5721               }
5722             else
5723               {
5724                 QFont f = QApplication::font();
5725                 f.setBold( TRUE );
5726                 if (nbSel==1)
5727                   {
5728                     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5729                     popup->removeItem(QAD_TopLabel_Popup_ID);
5730                     popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), QAD_TopLabel_Popup_ID, 0 );
5731                     if ( IObject->hasEntry() )
5732                       popup->setItemEnabled( 801, false );
5733                     else
5734                       popup->setItemEnabled( 801, true );
5735                     
5736                     if (IObject->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)))
5737                       {
5738                         Standard_Boolean found;
5739                         Handle(GEOM_AISShape) Result = GeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
5740
5741                         if ( found )
5742                           {
5743                             if ( Result->DisplayMode() == 1 )
5744                               popup->changeItem(8021, tr("GEOM_MEN_WIREFRAME") );
5745                             else
5746                               popup->changeItem(8021, tr("GEOM_MEN_SHADING") );
5747                           }
5748                       }
5749
5750                     if ( !(v3d->isInViewer( IObject ) && v3d->isVisible( IObject )) )
5751                       popup->removeItem(QAD_Erase_Popup_ID);
5752                     else
5753                       popup->removeItem(QAD_Display_Popup_ID);
5754                     
5755                   }
5756                 else
5757                   {
5758                     popup->removeItem(QAD_DisplayOnly_Popup_ID);
5759                     popup->removeItem(QAD_TopLabel_Popup_ID);
5760                     popup->insertItem( new CustomItem ( tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f ),
5761                                       QAD_TopLabel_Popup_ID, 0 );
5762                     popup->setItemEnabled( 801, false );
5763                   }
5764               }
5765           return true;
5766         }
5767       else
5768         if ( theParent.compare("ObjectBrowser")==0 )
5769           {
5770             popup->removeItem(QAD_TopLabel_Popup_ID);
5771             int id = popup->idAt(0); // separator
5772             if (id < 0) popup->removeItem(id);
5773             
5774             // checking for GEOM label in the selected list
5775             SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5776             Handle(SALOME_InteractiveObject) anIObject;
5777
5778             bool useSubItems = false;
5779             bool needOpen = false;
5780             bool needDisplay = false;
5781             bool needErase = false;
5782             SALOMEDS::GenericAttribute_var aTmpAttr;
5783             for(;It.More();It.Next())
5784               {
5785                 anIObject = It.Value();
5786                 if (!anIObject->hasEntry())
5787                     continue;
5788                 
5789                 if (v3d->isInViewer(anIObject) && v3d->isVisible(anIObject)) 
5790                   needErase = true; 
5791                 else 
5792                   needDisplay = true;
5793                 SALOMEDS::SObject_var obj =
5794                   GeomGUI->myActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
5795                 if (!obj->_is_nil())
5796                   {
5797                     GEOM::GEOM_Shape_var aShape;
5798                     if (obj->FindAttribute(aTmpAttr, "AttributeIOR")) {
5799                       char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
5800                       if (str && strlen(str))
5801                         aShape = GeomGUI->myComponentGeom-> GetIORFromString(str);
5802                     }
5803                     else
5804                       if (obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5805                         needOpen = true;
5806                     if (aShape->_is_nil())
5807                       {
5808                         SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->
5809                           getStudyDocument()->NewChildIterator(obj);
5810                         while (anIter->More())
5811                           {
5812                             SALOMEDS::SObject_var subobj = anIter->Value();
5813                             if (subobj->FindAttribute(aTmpAttr, "AttributeIOR"))
5814                               {
5815                                 useSubItems = true;
5816                                 needErase = true;
5817                                 needDisplay = true;
5818                               }
5819                             else
5820                               if (subobj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5821                                 {
5822                                   needOpen = true;
5823                                   useSubItems = true;
5824                                 }
5825                             anIter->Next();
5826                           }
5827                       }
5828                   }
5829               }
5830             // remove useless popup items
5831             if (nbSel != 1) popup->removeItem(901); // rename
5832             if (useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
5833             if (!needOpen)
5834               {
5835                 int index = popup->indexOf(9024);
5836                 popup->removeItem(9024); // open
5837                 popup->removeItemAt(index); // separator under Open
5838
5839                 if (!needDisplay) popup->removeItem(QAD_Display_Popup_ID);
5840                 if (!needErase) popup->removeItem(QAD_Erase_Popup_ID);
5841                 if (!needDisplay && !needErase)
5842                   {
5843                     int id = popup->idAt(popup->count()-1); // last item
5844                     popup->removeItem(id); // separator
5845                   }
5846               }
5847             else
5848               {
5849                 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
5850                 popup->removeItem(QAD_Display_Popup_ID);
5851                 popup->removeItem(QAD_Erase_Popup_ID);
5852                 if (nbSel!=1)
5853                   {
5854                     int id = popup->idAt(popup->count()-1); // last item
5855                     popup->removeItem(id); // separator
5856                   }
5857               }
5858             return true;
5859           }
5860       // MESSAGE ( " CUSTOM POPUP VIEWER OCC done. ")
5861     }
5862   else
5863     if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
5864       {
5865         // MESSAGE ( " CUSTOM POPUP VIEWER VTK ")
5866         if ( ( theParent.compare("Viewer")==0 ) )
5867           {
5868             
5869             popup->setItemEnabled( 8033, false );
5870             if (theObject.compare("Component") == 0)
5871               {
5872                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
5873                 return true;
5874               } 
5875
5876           //int id = popup->idAt(0);
5877           QFont f = QApplication::font();
5878           f.setBold( TRUE );
5879           
5880           if (nbSel==1)
5881             {
5882               Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5883               popup->removeItem(QAD_TopLabel_Popup_ID);
5884               popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), QAD_TopLabel_Popup_ID, 0 );
5885               if ( IObject->hasEntry() )
5886                 {
5887                   popup->setItemEnabled( 801, false );
5888                   SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
5889                   SALOMEDS::SObject_var SO = aStudy->FindObjectID( IObject->getEntry() );
5890                   SALOMEDS::GenericAttribute_var anAttr;
5891                   SALOMEDS::AttributeIOR_var     anIOR;
5892                   if ( !SO->_is_nil() )
5893                     {
5894                       if (SO->FindAttribute(anAttr, "AttributeIOR") )
5895                         {
5896                           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5897                           Standard_Boolean found;
5898                           GEOM_Actor* Result = GeomGUI->ConvertIORinGEOMActor(anIOR->Value(), found, true);
5899                           if ( found )
5900                             {
5901                               if ( Result->getDisplayMode() == 1 )
5902                                 popup->changeItem(8021, "Wireframe" );
5903                               else
5904                                 popup->changeItem(8021, "Shading" );
5905                               
5906                               if ( !Result->GetVisibility() )
5907                                 popup->removeItem(QAD_Erase_Popup_ID);
5908                               else
5909                                 popup->removeItem(QAD_Display_Popup_ID);                  
5910                             }
5911                           else
5912                             popup->removeItem(QAD_Erase_Popup_ID);
5913                         }
5914                     }
5915                 }
5916               else
5917                 popup->setItemEnabled( 801, true );
5918             }
5919           else
5920             {
5921               popup->removeItem(QAD_DisplayOnly_Popup_ID);
5922               popup->removeItem(QAD_TopLabel_Popup_ID);
5923               popup->insertItem( new CustomItem ( tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f ), QAD_TopLabel_Popup_ID, 0 );
5924               popup->setItemEnabled( 801, false );
5925             }
5926           return true;
5927         }
5928         else
5929           if ( theParent.compare("ObjectBrowser")==0 )
5930             {
5931               popup->removeItem(QAD_TopLabel_Popup_ID);
5932               int id = popup->idAt(0); // separator
5933               if (id < 0) popup->removeItem(id);
5934       
5935               // checking for GEOM label in the selected list
5936               SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5937               Handle(SALOME_InteractiveObject) anIObject;
5938               
5939               bool useSubItems = false;
5940               bool needOpen = false;
5941               bool needDisplay = false;
5942               bool needErase = false;
5943               SALOMEDS::GenericAttribute_var aTmpAttr;
5944               VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->
5945                                                getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5946               for(;It.More();It.Next())
5947                 {
5948                   anIObject = It.Value();
5949                   if ( !anIObject->hasEntry() )
5950                     continue;
5951                   
5952                   if (myRenderInter->isInViewer(anIObject) && myRenderInter->isVisible(anIObject)) 
5953                     needErase = true; 
5954                   else 
5955                     needDisplay = true;
5956
5957                   SALOMEDS::SObject_var obj = GeomGUI->myActiveStudy->getStudyDocument()
5958                     ->FindObjectID( anIObject->getEntry() );
5959                   if (!obj->_is_nil()) {
5960                     GEOM::GEOM_Shape_var aShape;
5961                     if (obj->FindAttribute(aTmpAttr, "AttributeIOR")){
5962                       char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
5963                       if (str && strlen(str))
5964                         aShape = GeomGUI->myComponentGeom->GetIORFromString(str);
5965                     }
5966                     else
5967                       if (obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5968                         needOpen = true;
5969                     if (aShape->_is_nil())
5970                       {
5971                         SALOMEDS::ChildIterator_var anIter =
5972                           GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
5973                         while (anIter->More())
5974                           {
5975                             SALOMEDS::SObject_var subobj = anIter->Value();
5976                             if (subobj->FindAttribute(aTmpAttr, "AttributeIOR"))
5977                               {
5978                                 useSubItems = true;
5979                                 needDisplay = true;
5980                                 needErase = true;
5981                               }
5982                             else
5983                               if (subobj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5984                                 {
5985                                   needOpen = true;
5986                                   useSubItems = true;
5987                                 }
5988                             anIter->Next();
5989                           }
5990                       }
5991                   }
5992                 }
5993               // remove useless popup items
5994               if (nbSel != 1) popup->removeItem(901); // rename
5995               if (useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
5996               if (!needOpen)
5997                 {
5998                   int index = popup->indexOf(9024);
5999                   popup->removeItem(9024); // open
6000                   popup->removeItemAt(index); // separator under Open
6001                   
6002                   if (!needDisplay) popup->removeItem(QAD_Display_Popup_ID);
6003                   if (!needErase) popup->removeItem(QAD_Erase_Popup_ID);
6004                   if (!needDisplay && !needErase)
6005                     {
6006                       int id = popup->idAt(popup->count()-1); // last item
6007                       popup->removeItem(id); // separator
6008                     }
6009                 }
6010               else
6011                 {
6012                   popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
6013                   popup->removeItem(QAD_Display_Popup_ID);
6014                   popup->removeItem(QAD_Erase_Popup_ID);
6015                   if (nbSel!=1)
6016                     {
6017                       int id = popup->idAt(popup->count()-1); // last item
6018                       popup->removeItem(id); // separator
6019                     }
6020                 }
6021               return true;
6022               // MESSAGE ( " CUSTOM POPUP VIEWER VTK done.")
6023             }
6024       } else
6025         { // other viewer types not supported.
6026           while (1)
6027             {
6028               int id = popup->idAt(0);
6029               if (id <= QAD_TopLabel_Popup_ID && id != -1)
6030                 popup->removeItemAt(0);
6031               else
6032                 break;
6033             }
6034           popup->removeItem(QAD_DisplayOnly_Popup_ID);  
6035           popup->removeItem(QAD_Display_Popup_ID);
6036           popup->removeItem(QAD_Erase_Popup_ID);
6037           int id = popup->idAt(popup->count()-1); // last item
6038           if (id < 0 && id != -1) popup->removeItem(id); // separator
6039           return false;
6040         }
6041   return false;
6042 }
6043
6044 void GeometryGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
6045 {
6046   /* Create or retrieve an object GeomGUI */
6047   GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
6048   
6049   SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
6050   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
6051   
6052   OCCViewer_Viewer3d* v3d;
6053   Handle(AIS_InteractiveContext) ic;
6054   vtkRenderer* Renderer;
6055
6056   if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
6057     v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6058     ic = v3d->getAISContext();
6059   } else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
6060     Renderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6061   } else
6062     return;
6063
6064   if (theIO.IsNull())
6065     MESSAGE("BuildPresentation(): null SALOME_InteractiveObject passed")
6066
6067   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
6068     // VTK
6069           
6070     SALOMEDS::SObject_var fatherSF = 
6071       aStudy->FindObjectID(GeomGUI->myActiveStudy->getActiveStudyFrame()->entry());
6072             
6073     SALOMEDS::SObject_var obj = aStudy->FindObjectID( theIO->getEntry() );
6074
6075     VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
6076
6077     SALOMEDS::GenericAttribute_var anAttr;
6078     SALOMEDS::AttributeName_var    aName;
6079     SALOMEDS::AttributeIOR_var     anIOR;
6080          
6081     if(myRenderInter->isInViewer(theIO)) {
6082       myRenderInter->Display(theIO, false);
6083     }
6084     else {
6085       // Create new actor
6086       if ( !obj->_is_nil() ) {
6087         if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
6088           // this SObject may be GEOM module root SObject
6089
6090           bool useSubItems = false;
6091           SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
6092           if (GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
6093             while (anIter->More() && !useSubItems) {
6094               SALOMEDS::SObject_var subobj = anIter->Value();
6095               SALOMEDS::GenericAttribute_var aTmpAttr;
6096               if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
6097                 if (!GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
6098                   anAttr = aTmpAttr;
6099                   obj = subobj;
6100                   useSubItems = true;
6101                 } else anIter->Next();
6102               } else anIter->Next();
6103             }
6104           }
6105
6106           while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
6107             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6108             GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
6109             TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
6110             
6111             if (obj->FindAttribute(anAttr, "AttributeName")) {
6112               aName = SALOMEDS::AttributeName::_narrow(anAttr);
6113               
6114               vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6115               vtkActorCollection* theAllActors = theRenderer->GetActors();
6116               theAllActors->InitTraversal();
6117               vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
6118               Handle(SALOME_InteractiveObject) anIObj;
6119               // don't create new study object if it already exists
6120               bool isDisplayed = false;
6121               while(!(actor==NULL)) {
6122                 SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
6123                 if (Gactor!=NULL) {
6124                   if (Gactor->hasIO()) {
6125                     if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
6126                       isDisplayed = true;
6127                       anIObj = Gactor->getIO();
6128                       if (!anIObj.IsNull()) myRenderInter->Display(anIObj, false);
6129                     }
6130                   }
6131                 }
6132                 actor=(vtkActor*)(theAllActors->GetNextActor());
6133               }
6134               if (!isDisplayed) {
6135                 // open transaction
6136                 QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy );
6137                 op->start();
6138                 
6139                 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
6140                 aStudyBuilder->Addreference(newObj1, obj);
6141                 // commit transaction
6142                 op->finish();
6143                 
6144                 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6145                 int themode = myRenderInter->GetDisplayMode();
6146                 
6147                 vtkActorCollection* theActors = 
6148                   GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
6149                 theActors->InitTraversal();
6150                 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
6151                 while(!(anActor==NULL)) {
6152                   GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
6153                   Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), Fatherior,"GEOM");
6154                   IO->setEntry(obj->GetID());
6155                   GActor->setIO( IO );
6156                   GActor->setName( theIO->getName() );
6157                   
6158                   theRenderer->AddActor(GActor);
6159                   //              renWin->Render();
6160                   anActor = (vtkActor*)theActors->GetNextActor();
6161                 }
6162               }
6163             }
6164             // next item iteration
6165             if (useSubItems) {
6166               anIter->Next();
6167               anAttr = SALOMEDS::GenericAttribute::_nil();
6168               while (anIter->More() && anAttr->_is_nil()) {
6169                 SALOMEDS::SObject_var subobject = anIter->Value();
6170                 SALOMEDS::GenericAttribute_var aTmpAttribute;
6171                 if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
6172                   anAttr = aTmpAttribute;
6173                   obj = subobject;
6174                 } else anIter->Next();
6175               }
6176             } else anAttr = SALOMEDS::GenericAttribute::_nil();
6177           }
6178         }
6179       }
6180     }
6181     // No viewer update should be done here!
6182     //myRenderInter->Render();
6183     //GeomGUI->myActiveStudy->updateObjBrowser( true );
6184   } else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
6185     SALOMEDS::SObject_var fatherSF = 
6186       aStudy->FindObjectID( GeomGUI->myActiveStudy->getActiveStudyFrame()->entry());
6187     SALOMEDS::GenericAttribute_var anAttr;
6188     SALOMEDS::AttributeName_var    aName;
6189     SALOMEDS::AttributeIOR_var     anIOR;
6190
6191     if ( v3d->isInViewer( theIO, true ) ) {
6192       Standard_Boolean found;
6193       Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( theIO, found, true );
6194       if ( found ) {
6195         ic->Display(aSh, false);
6196         ic->AddOrRemoveCurrentObject(aSh, false);
6197       }
6198       
6199     } else {
6200       SALOMEDS::SObject_var obj = aStudy->FindObjectID( theIO->getEntry() );          
6201       if ( !obj->_is_nil() ) {
6202         MESSAGE("BuildPresentation(): SObject not null")
6203         if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
6204           MESSAGE("BuildPresentation(): SObject has IOR")
6205           // this SObject may be GEOM module root SObject
6206
6207           bool useSubItems = false;
6208           SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
6209           if (GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
6210             while (anIter->More() && !useSubItems) {
6211               SALOMEDS::SObject_var subobj = anIter->Value();
6212               SALOMEDS::GenericAttribute_var aTmpAttr;
6213               if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
6214                 if (!GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
6215                   anAttr = aTmpAttr;
6216                   obj = subobj;
6217                   useSubItems = true;
6218                 } else anIter->Next();
6219               } else anIter->Next();
6220             }
6221           }
6222
6223           while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
6224             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6225             GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
6226             TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
6227             if (Shape.IsNull())
6228               MESSAGE("BuildPresentation(): TopoDS_Shape is null!")
6229             if (obj->FindAttribute(anAttr, "AttributeName")) {
6230               MESSAGE("BuildPresentation(): SObject has Name")
6231               aName = SALOMEDS::AttributeName::_narrow(anAttr);
6232               // searchin for already displayed objects with the same shape
6233               AIS_ListOfInteractive aDisplayed;
6234               ic->DisplayedObjects(aDisplayed);
6235               AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
6236               Handle(AIS_Shape) anAISShape;
6237               for(;anIObjects.More();anIObjects.Next()) {
6238                 anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
6239                 if (!anAISShape.IsNull()) {
6240                   if (anAISShape->Shape().IsSame(Shape)) break;
6241                   anAISShape.Nullify();
6242                 }
6243               }
6244               if (!anAISShape.IsNull()) {
6245                 if (!ic->IsDisplayed(anAISShape)) ic->Display(anAISShape, false);
6246               } else {
6247                 if (!useSubItems) {
6248                   // open transaction
6249                   QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy );
6250                   op->start();
6251                   if (fatherSF->_is_nil())
6252                     MESSAGE("BuildPresentation(): fatherSF is nil!")
6253                   SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
6254                   aStudyBuilder->Addreference(newObj1, obj);
6255                   // commit transaction
6256                   op->finish();
6257                 }
6258                 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
6259                 aSh->SetShadingColor( GeomGUI->myShadingColor );
6260                 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(),
6261                                                                                Fatherior,
6262                                                                                "GEOM");
6263                 IO->setEntry(obj->GetID());
6264                 aSh->setIO( IO );
6265                 aSh->setName( aName->Value() );
6266                 ic->Display (aSh, false);
6267                 if (!useSubItems) ic->AddOrRemoveCurrentObject(aSh, false);
6268               }
6269             }
6270             // next item iteration
6271             if (useSubItems) {
6272               anIter->Next();
6273               anAttr=SALOMEDS::GenericAttribute::_nil();
6274               while (anIter->More() && anAttr->_is_nil()) {
6275                 SALOMEDS::SObject_var subobject = anIter->Value();
6276                 SALOMEDS::GenericAttribute_var aTmpAttribute;
6277                 if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
6278                   anAttr = aTmpAttribute;
6279                   obj = subobject;
6280                 } else anIter->Next();
6281               }
6282             } else 
6283               anAttr = SALOMEDS::GenericAttribute::_nil();
6284           }
6285         }
6286       }
6287     }
6288     // No viewer update should be done here!
6289     //GeomGUI->myActiveStudy->updateObjBrowser( true );
6290     //ic->UpdateCurrentViewer();
6291   }
6292 }
6293
6294 //=======================================================================
6295 // function : Parameter()
6296 // purpose  : return a parameter (float) from a dialog box
6297 //
6298 //  avalue1    : is a float or integer used as a default value displayed
6299 //  aTitle1    : is the title for aValue1
6300 //  aTitle     : is the main title
6301 //  bottom     : maximum value to be entered
6302 //  top        : minimum value to be entered
6303 //  decimals   : number of decimals
6304 //=======================================================================
6305 double GeometryGUI::Parameter( Standard_Boolean& res,
6306                                const char* aValue1,
6307                                const char* aTitle1,
6308                                const char* aTitle,
6309                                const double bottom,
6310                                const double top,
6311                                const int decimals )
6312 {
6313   GeometryGUI_aParameterDlg * Dialog =
6314     new GeometryGUI_aParameterDlg(aValue1,
6315                                   aTitle1,
6316                                   QAD_Application::getDesktop(),
6317                                   aTitle,
6318                                   TRUE,
6319                                   0,
6320                                   bottom,
6321                                   top,
6322                                   decimals) ;
6323   int r = Dialog->exec() ;
6324   float X = 0.0 ;
6325   if ( r == QDialog::Accepted ) {
6326     res = Standard_True;
6327     X = Dialog->getValue();
6328   } else
6329     res = Standard_False;
6330   delete Dialog;
6331   return X;
6332 }
6333
6334
6335 //=======================================================================
6336 // function : OnSketchSegment()
6337 // purpose  : 
6338 //=======================================================================
6339 void GeometryGUI::OnSketchSegment()
6340 {
6341   this->mySketcher.ChangeMode(SEGMENT);
6342 }
6343
6344
6345 //=======================================================================
6346 // function : OnSketchArc()
6347 // purpose  : 
6348 //=======================================================================
6349 void GeometryGUI::OnSketchArc()
6350 {
6351   this->mySketcher.ChangeMode(ARC_CHORD);
6352 }
6353
6354 //=======================================================================
6355 // function : OnSketchSetAngle()
6356 // purpose  : 
6357 //=======================================================================
6358 void GeometryGUI::OnSketchSetAngle()
6359 {
6360   Standard_Real anAngle = this->mySketcher.GetSegmentAngle()/PI180;
6361   Sketch::fitInResol(anAngle); 
6362   Standard_Boolean res = false ;
6363   QString Value = QString("%1").arg( anAngle );
6364   anAngle = Parameter(res, Value, tr("GEOM_MEN_ANGLE"), tr("GEOM_MEN_ENTER_ANGLE"), -180.0, +180.0, 6 )*PI180 ;
6365
6366   if( res ) {
6367     this->mySketcher.SetSegmentAngle(anAngle);
6368     QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6369     QMenuData* pp;
6370     QMenuItem* item = Mb->findItem(3133,&pp);
6371     pp->setItemChecked(3133,false);
6372     item = Mb->findItem(3134,&pp);
6373     pp->setItemChecked(3134,false);
6374   }
6375   
6376 }
6377
6378
6379 //=======================================================================
6380 // function : OnSketchSetx()
6381 // purpose  : 
6382 //=======================================================================
6383 void GeometryGUI::OnSketchSetx()
6384 {
6385   Standard_Boolean res = false;
6386   double X = Parameter( res,
6387                         "0.",
6388                         tr("GEOM_MEN_X"),
6389                         tr("GEOM_MEN_SKETCHER_X"),
6390                         2.0 * Precision::Confusion(),
6391                         1E6,
6392                         6 ) ;
6393   if (res)
6394     this->mySketcher.SetXDimension(X);
6395   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6396   QMenuData* pp;
6397   QMenuItem* item = Mb->findItem(3133,&pp);
6398   pp->setItemChecked(3133,false);
6399   item = Mb->findItem(3134,&pp);
6400   pp->setItemChecked(3134,false);
6401 }
6402
6403 //=======================================================================
6404 // function : OnSketchSety()
6405 // purpose  : 
6406 //=======================================================================
6407 void GeometryGUI::OnSketchSety()
6408 {
6409   Standard_Boolean res = false;
6410   double Y = Parameter( res,
6411                         "0.",
6412                         tr("GEOM_MEN_Y"),
6413                         tr("GEOM_MEN_SKETCHER_Y"),
6414                         2.0 * Precision::Confusion(),
6415                         1E6,
6416                         6 ) ;
6417   if (res)
6418     this->mySketcher.SetYDimension(Y);
6419   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6420   QMenuData* pp;
6421   QMenuItem* item = Mb->findItem(3133,&pp);
6422   pp->setItemChecked(3133,false);
6423   item = Mb->findItem(3134,&pp);
6424   pp->setItemChecked(3134,false);
6425 }
6426
6427
6428 //=======================================================================
6429 // function : OnSketchDelete()
6430 // purpose  : 
6431 //=======================================================================
6432 void GeometryGUI::OnSketchDelete()
6433 {
6434   if (GeomGUI->mySketcher.GetmyEdgesNumber() == 1 ) {
6435     QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
6436     QMenuData* pp;
6437     QMenuItem* item = Mb->findItem(313,&pp);
6438     pp->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
6439     GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6440   }
6441
6442   if (this->mySketcher.Delete())
6443     GeomGUI->ResetState();
6444 }
6445
6446
6447 //=======================================================================
6448 // function : OnSketchClose()
6449 // purpose  : 
6450 //=======================================================================
6451 void GeometryGUI::OnSketchClose()
6452 {
6453   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6454   Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
6455
6456   TopoDS_Wire W = this->mySketcher.Close();
6457   if ( !W.IsNull() ) {
6458     //
6459     GEOM::GEOM_Gen::ListOfIOR_var listShapes = new GEOM::GEOM_Gen::ListOfIOR;
6460     listShapes->length(0);
6461     unsigned int i = 0;
6462
6463     BRepTools_WireExplorer Ex(W);
6464     while ( Ex.More() ) {
6465       TopoDS_Edge E = Ex.Current();
6466       gp_Pnt pt1 , pt2 ;
6467
6468       pt1 = BRep_Tool::Pnt(TopExp::FirstVertex(E));
6469       pt2 = BRep_Tool::Pnt(TopExp::LastVertex(E));
6470
6471       gp_Pnt CenterPoint;
6472       Handle(Geom_Curve) Curve;
6473       Handle(Geom_Circle) Circle;
6474       gp_Circ Circ;
6475       Standard_Real First,Last;
6476
6477       Curve = BRep_Tool::Curve(E,First,Last);
6478       if(Curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
6479         Circle = Handle(Geom_Circle)::DownCast(Curve); // pointer on geom_circ
6480         Circ   = Circle->Circ();                       // gp_Circ
6481         
6482         Curve->D0( (First + Last) / 2. , CenterPoint );
6483
6484         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6485         GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z() );
6486         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6487
6488         GEOM::GEOM_Shape_var arc;
6489
6490         try {
6491           arc = myComponentGeom->MakeArc(pI, pC, pE) ;
6492         }
6493         catch (const SALOME::SALOME_Exception& S_ex) {
6494           QtCatchCorbaException(S_ex);
6495         }
6496
6497         listShapes->length(i+1);
6498         listShapes[i] = strdup(arc->Name());
6499         i++;   
6500      } else {
6501         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6502         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6503         GEOM::GEOM_Shape_var segment;
6504
6505         try {
6506           segment = myComponentGeom->MakeEdge(pI,pE) ;
6507         }       
6508         catch (const SALOME::SALOME_Exception& S_ex) {
6509           QtCatchCorbaException(S_ex);
6510         }
6511
6512         listShapes->length(i+1);
6513         listShapes[i] = strdup(segment->Name());
6514         i++;
6515       }
6516       Ex.Next();
6517     }
6518     GEOM::GEOM_Shape_var Wire = myComponentGeom->MakeWire(listShapes) ;
6519     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, Wire);
6520     Standard_CString type;
6521     GetShapeTypeString(S,type);
6522     Wire->NameType( type );
6523
6524     if ( Display(Wire, "" )) {
6525       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6526     } 
6527   }
6528   GeomGUI->ResetState();
6529   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6530   QMenuData* pp;
6531   QMenuItem* item = Mb->findItem(313,&pp);
6532   pp->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
6533   GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6534 }
6535
6536
6537
6538 //=======================================================================
6539 // function : OnSketchEnd()
6540 // purpose  : 
6541 //=======================================================================
6542 void GeometryGUI::OnSketchEnd()
6543 {
6544   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6545   Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
6546
6547   TopoDS_Wire W = this->mySketcher.End();
6548   if (!W.IsNull()) {
6549     //
6550     GEOM::GEOM_Gen::ListOfIOR_var listShapes = new GEOM::GEOM_Gen::ListOfIOR;
6551     listShapes->length(0);
6552     unsigned int i = 0;
6553
6554     BRepTools_WireExplorer Ex(W);
6555     while ( Ex.More() ) {
6556       TopoDS_Edge E = TopoDS::Edge( Ex.Current() );
6557       
6558       gp_Pnt pt1 , pt2 ;
6559       pt1 = BRep_Tool::Pnt(TopExp::FirstVertex(E));
6560       pt2 = BRep_Tool::Pnt(TopExp::LastVertex(E));
6561
6562       gp_Pnt CenterPoint;
6563       Handle(Geom_Curve) Curve;
6564       Handle(Geom_Circle) Circle;
6565       gp_Circ Circ;
6566       Standard_Real First,Last;
6567       
6568       Curve = BRep_Tool::Curve(E,First,Last);
6569       if(Curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
6570         Circle = Handle(Geom_Circle)::DownCast(Curve); // pointer on geom_circ
6571         Circ   = Circle->Circ();                       // gp_Circ
6572         
6573         Curve->D0( (First + Last) / 2. , CenterPoint );
6574
6575         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6576         GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z() );
6577         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6578
6579         GEOM::GEOM_Shape_var arc;
6580
6581         try {
6582           arc = myComponentGeom->MakeArc(pI, pC, pE) ;
6583         }
6584         catch (const SALOME::SALOME_Exception& S_ex) {
6585           QtCatchCorbaException(S_ex);
6586         }
6587                 
6588         listShapes->length(i+1);
6589         listShapes[i] = strdup(arc->Name());
6590         i++;   
6591       } else {
6592         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6593         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6594         GEOM::GEOM_Shape_var segment;
6595         
6596         try {
6597           segment = myComponentGeom->MakeEdge(pI,pE) ;
6598         }
6599         catch (const SALOME::SALOME_Exception& S_ex) {
6600           QtCatchCorbaException(S_ex);
6601         }
6602         
6603         listShapes->length(i+1);
6604         listShapes[i] = strdup(segment->Name());
6605         i++;
6606       }
6607       Ex.Next();
6608     }
6609
6610     GEOM::GEOM_Shape_var Wire = myComponentGeom->MakeWire(listShapes) ;
6611     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, Wire);
6612     Standard_CString type;
6613     GetShapeTypeString(S,type);
6614     Wire->NameType( type );
6615
6616     if ( Display(Wire, "") ) {
6617       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6618     }
6619   }
6620   GeomGUI->ResetState();
6621   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6622   QMenuData* pp;
6623   QMenuItem* item = Mb->findItem(313,&pp);
6624   pp->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
6625   GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6626 }
6627
6628 //=======================================================================
6629 // function : OnSettingsNoconstraint()
6630 // purpose  : 
6631 //=======================================================================
6632 void GeometryGUI::OnSettingsNoconstraint() 
6633 {
6634     this->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6635 }
6636
6637 //=======================================================================
6638 // function : OnSettingsPerpendicular()
6639 // purpose  : 
6640 //=======================================================================
6641 void GeometryGUI::OnSettingsPerpendicular() 
6642 {
6643     this->mySketcher.SetTransitionStatus(PERPENDICULAR);
6644 }
6645
6646 //=======================================================================
6647 // function : OnSettingsTangent()
6648 // purpose  : 
6649 //=======================================================================
6650 void GeometryGUI::OnSettingsTangent() 
6651 {
6652   this->mySketcher.SetTransitionStatus(TANGENT);
6653 }
6654
6655 //=======================================================================
6656 // function : OnSketchOptionsOnoffangledimension()
6657 // purpose  : 
6658 //=======================================================================
6659 void GeometryGUI::OnSketchOptionsOnoffangledimension()
6660 {
6661   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6662   QMenuData* pp;
6663   QMenuItem* item = Mb->findItem(10011,&pp);
6664   pp->setItemChecked(10011,!pp->isItemChecked(10011));
6665   this->mySketcher.SetParameterVisibility(ANGLE_PARAMETER,pp->isItemChecked(10011));
6666 }
6667
6668 //=======================================================================
6669 // function : OnSketchOptionsOnofflengthdimension()
6670 // purpose  : 
6671 //=======================================================================
6672 void GeometryGUI::OnSketchOptionsOnofflengthdimension()
6673 {
6674   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6675   QMenuData* pp;
6676   QMenuItem* item = Mb->findItem(10010,&pp);
6677   pp->setItemChecked(10010,!pp->isItemChecked(10010));
6678   this->mySketcher.SetParameterVisibility(LENGTH_PARAMETER,pp->isItemChecked(10010));
6679 }
6680
6681 //=======================================================================
6682 // function : OnSketchOptionsOnoffradiusdimension()
6683 // purpose  : 
6684 //=======================================================================
6685 void GeometryGUI::OnSketchOptionsOnoffradiusdimension()
6686 {
6687   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6688   QMenuData* pp;
6689   QMenuItem* item = Mb->findItem(10012,&pp);
6690   pp->setItemChecked(10012,!pp->isItemChecked(10012));
6691   this->mySketcher.SetParameterVisibility(RADIUS_PARAMETER,pp->isItemChecked(10012));
6692 }
6693
6694
6695 //=======================================================================
6696 // function : OnSketchOptionsOnoffxdimension()
6697 // purpose  : 
6698 //=======================================================================
6699 void GeometryGUI::OnSketchOptionsOnoffxdimension()
6700 {
6701   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6702   QMenuData* pp;
6703   QMenuItem* item = Mb->findItem(10013,&pp);
6704   pp->setItemChecked(10013,!pp->isItemChecked(10013));
6705   this->mySketcher.SetParameterVisibility(XVALUE_PARAMETER,pp->isItemChecked(10013));
6706 }
6707
6708 //=======================================================================
6709 // function : OnSketchOptionsOnoffydimension()
6710 // purpose  : 
6711 //=======================================================================
6712 void GeometryGUI::OnSketchOptionsOnoffydimension()
6713 {
6714   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6715   QMenuData* pp;
6716   QMenuItem* item = Mb->findItem(10014,&pp);
6717   pp->setItemChecked(10014,!pp->isItemChecked(10014));
6718   this->mySketcher.SetParameterVisibility(YVALUE_PARAMETER,pp->isItemChecked(10014));
6719 }
6720
6721
6722 //=======================================================================
6723 // function : Archimede()
6724 // purpose  : 
6725 //=======================================================================
6726 void GeometryGUI::Archimede( const Handle(SALOME_InteractiveObject)& IO, 
6727                              const double aWeight,
6728                              const double aWaterDensity,
6729                              const double aMeshingDeflection )
6730 {
6731   try {
6732     if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
6733       Handle(GEOM_InteractiveObject) GIO =
6734         Handle(GEOM_InteractiveObject)::DownCast( IO );
6735       GEOM::GEOM_Shape_var Shape = GeomGUI->myComponentGeom->GetIORFromString( GIO->getIOR() );
6736       
6737       GEOM::GEOM_Shape_var Result = GeomGUI->myComponentGeom->Archimede( Shape, aWeight, aWaterDensity, aMeshingDeflection);
6738       Result->NameType(tr("GEOM_PLANE"));
6739       if ( Display(Result, "") ) {
6740         QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6741       }
6742       return;
6743     }
6744     if ( IO->hasEntry() ) {
6745       SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
6746       SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
6747       SALOMEDS::GenericAttribute_var anAttr;
6748       SALOMEDS::AttributeIOR_var     anIOR;
6749       if ( !obj->_is_nil() ) {
6750         if (obj->FindAttribute(anAttr, "AttributeIOR")) {
6751           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6752           GEOM::GEOM_Shape_var Shape = GeomGUI->myComponentGeom->GetIORFromString( anIOR->Value() );
6753           GEOM::GEOM_Shape_var Result = GeomGUI->myComponentGeom->Archimede( Shape, aWeight, aWaterDensity, aMeshingDeflection);
6754           Result->NameType(tr("GEOM_PLANE"));
6755           if ( Display(Result, "") ) {
6756             QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6757           }
6758         }
6759       }
6760     }
6761
6762   }
6763   catch (const SALOME::SALOME_Exception& S_ex) {
6764     QtCatchCorbaException(S_ex);
6765   }
6766 }
6767
6768
6769 //=====================================================================================
6770 // EXPORTED METHODS
6771 //=====================================================================================
6772 extern "C"
6773 {
6774   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
6775   {
6776     return GeometryGUI::OnGUIEvent(theCommandID, parent);
6777   }
6778
6779   bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
6780   {
6781     return GeometryGUI::OnKeyPress (pe, parent, studyFrame);
6782   }
6783
6784   bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
6785   {
6786     return GeometryGUI::OnMousePress (pe, parent, studyFrame);
6787   }
6788
6789   bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
6790   {
6791     return GeometryGUI::OnMouseMove (pe, parent, studyFrame);
6792   }
6793
6794   bool SetSettings ( QAD_Desktop* parent )
6795   {
6796     return GeometryGUI::SetSettings( parent );
6797   }
6798
6799   bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
6800                      const QString & theParent, const QString & theObject )
6801   {
6802      return GeometryGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
6803   }
6804
6805   void definePopup ( QString & theContext, QString & theParent, QString & theObject )
6806   {
6807     GeometryGUI::DefinePopup( theContext, theParent, theObject );
6808   }
6809   
6810   bool activeStudyChanged ( QAD_Desktop* parent )
6811   {
6812     GeometryGUI::activeStudyChanged( parent );
6813   }
6814
6815   void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
6816   {
6817     GeometryGUI::BuildPresentation(theIO);
6818   }
6819
6820   void supportedViewType(int* buffer, int bufferSize)
6821   {
6822     if (!buffer || !bufferSize) return;
6823     buffer[0] = (int)VIEW_OCC;
6824     if (--bufferSize) buffer[1] = (int)VIEW_VTK;
6825   }
6826 }
6827
6828 //=====================================================================================
6829 // function : OnFilletGetAll()
6830 // purpose  :
6831 //=====================================================================================
6832 bool GeometryGUI::OnFilletGetAll(const TopoDS_Shape& ShapeTopo, const double Radius, const int SubShapeType, const char* ShapeTopoIOR)
6833 {
6834   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
6835   ListOfID->length(0);
6836
6837   SALOMEDS::Study_var   aStudy = myActiveStudy->getStudyDocument();
6838   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR );
6839   if ( theObj->_is_nil() ) {
6840     myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
6841     return false ;
6842   }
6843   
6844   try {
6845     if( Radius <= Precision::Confusion() )
6846       return false;
6847
6848     GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
6849     GEOM::GEOM_Shape_var result = myComponentGeom->MakeFillet(aShape, Radius, SubShapeType, ListOfID) ;
6850     if ( result->_is_nil() ) {
6851       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
6852       return  false;
6853     }
6854     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
6855     Standard_CString type;
6856     GetShapeTypeString(S,type);
6857     result->NameType( type );
6858
6859     if ( Display( result, "" ))
6860       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
6861   }
6862   catch (const SALOME::SALOME_Exception& S_ex) {
6863     QtCatchCorbaException(S_ex);
6864   }
6865   return true;
6866 }
6867
6868 //=====================================================================================
6869 // function : OnFilletGetSelected()
6870 // purpose  :
6871 //=====================================================================================
6872 bool GeometryGUI::OnFilletGetSelected(const TopoDS_Shape& ShapeTopo,
6873                                       const char* ShapeTopoIOR,
6874                                       const double Radius,
6875                                       const int SubShapeType,
6876                                       Standard_Integer& aLocalContextId,
6877                                       bool& myUseLocalContext )
6878 {
6879   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
6880     return false;
6881   }
6882
6883   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6884   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
6885   
6886   if( myUseLocalContext == false ) {
6887     /*  No local context opened for fillet method */
6888     myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
6889     return false ;
6890   }
6891   
6892   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
6893   ic->InitSelected();
6894   int nbSelected = ic->NbSelected();
6895   int i = 0;
6896   ic->InitSelected();
6897
6898   while(ic->MoreSelected()) {
6899     TopoDS_Shape s = ic->SelectedShape();
6900     if ( s.ShapeType() == TopAbs_FACE ) {
6901       TopExp_Explorer Exp( s, TopAbs_EDGE );
6902       TopTools_MapOfShape M ;
6903       while ( Exp.More() ) {
6904         if( M.Add(Exp.Current() )) { /* if a new edge : do not add doublons indices */
6905           ListOfID->length( i + 1 );
6906           ListOfID[i] = GetIndex( Exp.Current(), ShapeTopo, (int)TopAbs_EDGE ) ;
6907           i++ ;
6908         }
6909         Exp.Next(); 
6910       }  
6911     }
6912     else {
6913       ListOfID->length( i + 1 );
6914       ListOfID[i] = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType );
6915       i++;
6916     }
6917     ic->NextSelected();
6918   }
6919
6920   GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
6921   GEOM::GEOM_Shape_var aResult ;
6922   try {
6923     aResult = myComponentGeom->MakeFillet( aShape, Radius, 6, ListOfID );
6924
6925     /* local context from DialogBox */
6926     ic->CloseLocalContext(aLocalContextId) ;
6927     myUseLocalContext = false ;
6928
6929     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult);
6930     Standard_CString type;
6931     GetShapeTypeString(S,type);
6932     aResult->NameType( type );
6933
6934     if ( Display( aResult, "") )
6935       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
6936   }
6937   catch (const SALOME::SALOME_Exception& S_ex) {
6938     QtCatchCorbaException(S_ex);
6939   }
6940
6941   if ( myUseLocalContext ) {
6942     /* local context from DialogBox */
6943     ic->CloseLocalContext(aLocalContextId) ;
6944     myUseLocalContext = false ;
6945   }
6946
6947   this->OnDisplayAll(true);
6948   myActiveStudy->updateObjBrowser();
6949   myDesktop->putInfo (tr("GEOM_PRP_READY"));
6950
6951   return true ;  
6952 }
6953
6954 //=====================================================================================
6955 // function : OnChamferGetAll()
6956 // purpose  :
6957 //=====================================================================================
6958 bool GeometryGUI::OnChamferGetAll(const TopoDS_Shape& ShapeTopo, const double D1, const double D2, const int SubShapeType, const char* ShapeTopoIOR)
6959 {
6960  GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
6961   ListOfID->length(0);
6962
6963   SALOMEDS::Study_var   aStudy = myActiveStudy->getStudyDocument();
6964   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR );
6965   if ( theObj->_is_nil() ) {
6966     myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
6967     return false ;
6968   }
6969   
6970   try {
6971     if( D1 <= Precision::Confusion() )
6972       return false;
6973     if( D2 <= Precision::Confusion() )
6974       return false;
6975
6976     GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
6977     GEOM::GEOM_Shape_var result = myComponentGeom->MakeChamfer(aShape, D1, D2, SubShapeType, ListOfID) ;
6978     if ( result->_is_nil() ) {
6979       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
6980       return  false;
6981     }
6982
6983     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
6984     Standard_CString type;
6985     GetShapeTypeString(S,type);
6986     result->NameType( type );
6987
6988     if ( Display( result, "") )
6989       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
6990   }
6991   catch (const SALOME::SALOME_Exception& S_ex) {
6992     QtCatchCorbaException(S_ex);
6993   }
6994   return true;
6995 }
6996
6997 //=====================================================================================
6998 // function : OnChamferGetSelected()
6999 // purpose  :
7000 //=====================================================================================
7001 bool GeometryGUI::OnChamferGetSelected(const TopoDS_Shape& ShapeTopo,
7002                                        const char* ShapeTopoIOR,
7003                                        const double D1, const double D2, const int SubShapeType,
7004                                        Standard_Integer& aLocalContextId,
7005                                        bool& myUseLocalContext)
7006 {
7007   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
7008     return false;
7009   }
7010   
7011   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
7012   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
7013   
7014   if( myUseLocalContext == false ) {
7015     /* No local context opened for chamfer method */
7016     myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
7017     return false ;
7018   }
7019   
7020   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
7021   ic->InitSelected();
7022   int nbSelected = ic->NbSelected();
7023   int i = 0;
7024   ic->InitSelected();
7025
7026   while(ic->MoreSelected()) {
7027     TopoDS_Shape s = ic->SelectedShape();
7028     if ( s.ShapeType() == TopAbs_FACE ) {
7029       TopExp_Explorer Exp( s, TopAbs_EDGE );
7030       TopTools_MapOfShape M ;
7031       while ( Exp.More() ) {
7032         if( M.Add(Exp.Current() )) { /* if a new edge : do not add doublons indices */
7033           ListOfID->length( i + 1 );
7034           ListOfID[i] = GetIndex( Exp.Current(), ShapeTopo, (int)TopAbs_EDGE ) ;
7035           i++ ;
7036         }
7037         Exp.Next(); 
7038       }  
7039     }
7040     else {
7041       ListOfID->length( i + 1 );
7042       ListOfID[i] = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType ) ;
7043       i++;
7044     }
7045     ic->NextSelected();
7046   }
7047   
7048   GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
7049   GEOM::GEOM_Shape_var aResult ;
7050   try {
7051     aResult = myComponentGeom->MakeChamfer( aShape, D1, D2, 6, ListOfID );
7052
7053     /* local context from DialogBox */
7054     ic->CloseLocalContext(aLocalContextId) ;
7055     myUseLocalContext = false ;
7056
7057     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult);
7058     Standard_CString type;
7059     GetShapeTypeString(S,type);
7060     aResult->NameType( type );
7061
7062     if ( Display( aResult, "") )
7063       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
7064   }
7065   catch (const SALOME::SALOME_Exception& S_ex) {
7066     QtCatchCorbaException(S_ex);
7067   }
7068
7069   if ( myUseLocalContext ) {
7070     /* local context from DialogBox */
7071     ic->CloseLocalContext(aLocalContextId) ;
7072     myUseLocalContext = false ;
7073   }
7074
7075   this->OnDisplayAll(true);
7076   myActiveStudy->updateObjBrowser();
7077   myDesktop->putInfo (tr("GEOM_PRP_READY"));
7078
7079   return true ;  
7080 }
7081
7082 //=====================================================================================
7083 // function : MakeCDGAndDisplay()
7084 // purpose  :
7085 //=====================================================================================
7086 void GeometryGUI::MakeCDGAndDisplay(GEOM::GEOM_Shape_ptr Shape)
7087 {
7088   try {
7089     GEOM::GEOM_Shape_var result = myComponentGeom->MakeCDG( Shape );
7090     if ( result->_is_nil() ) {
7091       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
7092       return ;
7093     }
7094     result->NameType( tr("GEOM_POINT") );
7095     if ( Display( result ) )
7096       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
7097   }  
7098   catch (const SALOME::SALOME_Exception& S_ex) {
7099     QtCatchCorbaException(S_ex);
7100   }
7101   return  ;
7102 }
7103
7104 bool GeometryGUI::SObjectExist(SALOMEDS::SObject_ptr theFatherObject, const char* IOR) {
7105   SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
7106   SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theFatherObject);
7107   SALOMEDS::SObject_var RefSO;
7108   SALOMEDS::GenericAttribute_var anAttr;
7109   SALOMEDS::AttributeIOR_var     anIOR;
7110   for (; it->More();it->Next()) {
7111     SALOMEDS::SObject_var SO= it->Value();
7112     if (SO->FindAttribute(anAttr, "AttributeIOR") ) {
7113       anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
7114       if ( strcmp( anIOR->Value(), IOR ) == 0 )
7115         return true;
7116     }
7117     if ( SO->ReferencedObject( RefSO ) ) {
7118       if (RefSO->FindAttribute(anAttr, "AttributeIOR") ) {
7119         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
7120         if ( strcmp( anIOR->Value(), IOR ) == 0 )
7121           return true;
7122       }
7123     }
7124   }
7125   return false;
7126 }