Salome HOME
NRI : Merge from 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", "GEOM");
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","GEOM");
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       aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) );
4995       anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
4996       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
4997       aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
4998       if (aLocked) aStudy->GetProperties()->SetLocked(true);
4999       op->finish();
5000     }
5001 //      if (aLocked) return false;
5002     aStudyBuilder->DefineComponentInstance( father, myComponentGeom );
5003     father->ComponentIOR( Fatherior );
5004
5005     QString nameShape = QAD_Tools::getFileNameFromPath(file,false) +  QString("_%1").arg(this->myNbGeom++);
5006
5007     if ( Display ( aShape, strdup(nameShape.latin1())) ) {
5008       myActiveStudy->setMessage( tr("GEOM_INF_LOADED").arg(QAD_Tools::getFileNameFromPath( file )) );
5009       myDesktop->putInfo( tr("GEOM_PRP_READY"));
5010     }
5011   }
5012   QApplication::restoreOverrideCursor();
5013   return true ;
5014 }
5015
5016
5017 //=====================================================================================
5018 // function : Export
5019 // purpose  : BRep, Iges, Step
5020 //=====================================================================================
5021 bool GeometryGUI::Export( )
5022 {
5023   SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5024   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
5025
5026   GEOM::GEOM_Shape_var aShape;
5027
5028   static QString filters[] = { tr("GEOM_MEN_IMPORT_BREP"),
5029                                tr("GEOM_MEN_IMPORT_IGES"),
5030                                tr("GEOM_MEN_IMPORT_STEP") };
5031   
5032   SALOME_Selection* Sel = SALOME_Selection::Selection( this->myActiveStudy->getSelection() );
5033   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5034
5035   switch ( GeomGUI->myState )
5036     {
5037     case 121 :
5038       {
5039         for(;It.More();It.Next()) {
5040           QApplication::restoreOverrideCursor();
5041           Handle(SALOME_InteractiveObject) IObject = It.Value();
5042           Standard_Boolean found;
5043           GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5044           //      Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true);
5045           if ( found ) {
5046             QString file = QAD_FileDlg::getFileName(myDesktop, 
5047                                                     QString( IObject->getName() ) + ".brep",
5048                                                     tr("GEOM_MEN_IMPORT_BREP"),
5049                                                     tr("GEOM_MEN_EXPORT"),
5050                                                     false);
5051             if ( !file.isEmpty() && !aShape->_is_nil() ) {
5052               QApplication::setOverrideCursor( Qt::waitCursor );
5053               //      Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
5054               try {
5055                 GeomGUI->myComponentGeom->ExportBREP(strdup( file.latin1()), aShape);
5056               }  
5057               catch (const SALOME::SALOME_Exception& S_ex) {
5058                 QtCatchCorbaException(S_ex);
5059               }
5060             }
5061           }
5062         }
5063         break;
5064       }
5065     case 122 :
5066       {
5067         for(;It.More();It.Next()) {
5068           QApplication::restoreOverrideCursor();
5069           Handle(SALOME_InteractiveObject) IObject = It.Value();
5070           Standard_Boolean found;
5071           GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5072           //      Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true);
5073           if ( found ) {
5074             QString file = QAD_FileDlg::getFileName(myDesktop, 
5075                                                     QString( IObject->getName() ) + ".igs",
5076                                                     tr("GEOM_MEN_IMPORT_IGES"),
5077                                                     tr("GEOM_MEN_EXPORT"),
5078                                                     false);
5079             if ( !file.isEmpty() && !aShape->_is_nil() ) {
5080               QApplication::setOverrideCursor( Qt::waitCursor );
5081               try {
5082                 GeomGUI->myComponentGeom->ExportIGES(strdup( file.latin1()), aShape);
5083               }  
5084               catch (const SALOME::SALOME_Exception& S_ex) {
5085                 QtCatchCorbaException(S_ex);
5086               }
5087 //            //VRV: OCC 4.0 migration
5088 //            IGESControl_Controller::Init();
5089 //            IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
5090 //                                       Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
5091 //            //VRV: OCC 4.0 migration
5092
5093 //            ICW.AddShape (Shape->Shape());
5094 //            ICW.ComputeModel();
5095 //            Standard_Boolean result = ICW.Write( strdup(file.latin1()) );
5096             }
5097           }
5098         }
5099         break;
5100       }
5101
5102     case 123 :
5103       {
5104 //      bool test = false ;
5105 //      IFSelect_ReturnStatus status ;
5106 //      //VRV: OCC 4.0 migration
5107 //      STEPControl_Writer aWriter;
5108 //      //VRV: OCC 4.0 migration
5109         QString file;
5110
5111         for( ; It.More(); It.Next() ) {
5112 //        GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5113           QApplication::restoreOverrideCursor();
5114           Handle(SALOME_InteractiveObject) IObject = It.Value();
5115           Standard_Boolean found;
5116           GEOM::GEOM_Shape_var aShape = GeomGUI->ConvertIOinGEOMShape(IObject, found);
5117           //      Handle(GEOM_AISShape) Shape = ConvertIOinGEOMAISShape(IObject, found, true);
5118           if ( found ) {
5119             file = QAD_FileDlg::getFileName(myDesktop, 
5120                                             QString( IObject->getName() ) + ".stp",
5121                                             tr("GEOM_MEN_IMPORT_STEP"),
5122                                             tr("GEOM_MEN_EXPORT"),
5123                                             false);
5124             if ( !file.isEmpty() && !aShape->_is_nil() ) {
5125
5126               QApplication::setOverrideCursor( Qt::waitCursor ) ;       
5127               try {   
5128                 GeomGUI->myComponentGeom->ExportSTEP(strdup( file.latin1()), aShape);   
5129               }  
5130               catch (const SALOME::SALOME_Exception& S_ex) {
5131                 QtCatchCorbaException(S_ex);
5132               }
5133 //            //VRV: OCC 4.0 migration
5134 //            status = aWriter.Transfer( Shape->Shape(), STEPControl_ManifoldSolidBrep ) ;
5135 //            //VRV: OCC 4.0 migration
5136 //            test = true ;
5137 //            if ( status != IFSelect_RetDone ) {
5138 //              QApplication::restoreOverrideCursor() ;
5139 //              return false ;
5140 //            }
5141             }
5142           }
5143         }
5144 //      if(test) {
5145 //        status = aWriter.Write( strdup(file.latin1()) ) ;
5146 //        QApplication::restoreOverrideCursor() ;
5147 //        return status ;
5148 //      }
5149         break;
5150       }
5151
5152     }
5153   QApplication::restoreOverrideCursor() ;
5154 }
5155
5156
5157 //=====================================================================================
5158 // function : Display()
5159 // purpose  : Displays a CORBA shape
5160 //=====================================================================================
5161 bool GeometryGUI::Display( GEOM::GEOM_Shape_ptr aShape, 
5162                            Standard_CString name)
5163 {
5164   // MESSAGE ( "GeometryGUI::Display init ") 
5165   Handle(GEOM_InteractiveObject) IO;
5166   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5167   Sel->ClearIObjects();
5168
5169   if( aShape->_is_nil() ) {
5170     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(),
5171                             tr ("GEOM_WRN_WARNING"),
5172                             tr ("GEOM_PRP_ABORT"),
5173                             tr ("GEOM_BUT_OK") );
5174     return false ;
5175   }
5176   
5177   TopoDS_Shape shape = ShapeReader.GetShape(myComponentGeom, aShape);
5178
5179   if ( shape.IsNull() )
5180     return false;
5181
5182   SALOMEDS::Study_var            aStudy = myActiveStudy->getStudyDocument();
5183   SALOMEDS::StudyBuilder_var     aStudyBuilder = aStudy->NewBuilder();
5184   SALOMEDS::GenericAttribute_var anAttr;
5185   SALOMEDS::AttributeName_var    aName;
5186   SALOMEDS::AttributePixMap_var    aPixmap;
5187
5188   SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
5189   int aLocked = false;
5190   if (father->_is_nil()) {
5191     QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5192     op->start();
5193     aLocked = aStudy->GetProperties()->IsLocked();
5194     if (aLocked) aStudy->GetProperties()->SetLocked(false);
5195     father = aStudyBuilder->NewComponent("GEOM");
5196     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
5197     aName = SALOMEDS::AttributeName::_narrow(anAttr);
5198     //    aName->SetValue( tr("GEOM_MEN_COMPONENT") );
5199     aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) );
5200     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
5201     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
5202     aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
5203     myActiveStudy->updateObjBrowser();
5204     if (aLocked) aStudy->GetProperties()->SetLocked(true);
5205     op->finish();
5206   }
5207 //    if (aLocked) return false;
5208
5209   aStudyBuilder->DefineComponentInstance( father, myComponentGeom );
5210   father->ComponentIOR( Fatherior );
5211
5212   TCollection_AsciiString nameG("");
5213   Standard_CString Type;
5214   if ( TCollection_AsciiString(name).IsEqual(Standard_CString("")) ) {
5215     if ( TCollection_AsciiString(aShape->NameType()).IsEqual(Standard_CString("")) ) {
5216       Standard_CString type;
5217       GetShapeTypeString(shape,type);
5218       aShape->NameType( type );
5219       nameG += TCollection_AsciiString( type ) + TCollection_AsciiString("_") + 
5220         TCollection_AsciiString( GeomGUI->myNbGeom++ ) + TCollection_AsciiString("\0");
5221     } else
5222       nameG += TCollection_AsciiString( aShape->NameType()) + TCollection_AsciiString("_") + 
5223         TCollection_AsciiString( GeomGUI->myNbGeom++ ) + TCollection_AsciiString("\0");
5224   } else 
5225     nameG = TCollection_AsciiString(name);
5226   
5227   // VTK
5228   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5229     VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5230     
5231     vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5232     int themode = myRenderInter->GetDisplayMode();
5233
5234     vtkActorCollection* theActors = 
5235       GEOM_AssemblyBuilder::BuildActors(shape,0,themode,Standard_True);
5236     theActors->InitTraversal();
5237     vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
5238
5239     IO = new GEOM_InteractiveObject(aShape->Name(),
5240                                     Fatherior,
5241                                     "GEOM");
5242     while(!(anActor==NULL)) {
5243       GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
5244       GActor->setIO( IO );
5245       GActor->setName( nameG.ToCString() );
5246       
5247       theRenderer->AddActor(GActor);
5248       anActor = (vtkActor*)theActors->GetNextActor();
5249     }
5250   } 
5251   // OCC
5252   else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5253     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
5254     Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5255     Handle(GEOM_AISShape) theResult = new GEOM_AISShape( shape, nameG.ToCString() );
5256     theResult->SetShadingColor( myShadingColor );
5257     IO = new GEOM_InteractiveObject(aShape->Name(),
5258                                     Fatherior,
5259                                     "GEOM");
5260     theResult->setIO( IO );
5261     theResult->setName( nameG.ToCString() );
5262     
5263     /* Precaution : close any local context to permit the display */
5264     if ( ic->HasOpenedContext() ) {
5265       ic->CloseAllContexts();
5266     }
5267     
5268 //     if(isInfinite)
5269 //       theResult->SetInfiniteState() ;
5270     
5271     ic->Display(theResult);
5272   }
5273
5274   Sel->AddIObject( IO, false );
5275   myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5276   if ( Settings_AddInStudy )
5277     GeomGUI->AddInStudy( false, IO );
5278   
5279   return true;
5280 }
5281
5282
5283 //=====================================================================================
5284 // function : AddInStudy() 
5285 // purpose  : anIOShape or a selected shape
5286 //=====================================================================================
5287 bool GeometryGUI::AddInStudy( bool selection,
5288                               const Handle(SALOME_InteractiveObject)& anIO)
5289 {
5290   SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5291   if ( !( !Settings_AddInStudy || selection ) ) {
5292     Sel->ClearIObjects();
5293   }
5294
5295   SALOMEDS::Study_var               aStudy = myActiveStudy->getStudyDocument();
5296   SALOMEDS::StudyBuilder_var        aStudyBuilder = aStudy->NewBuilder();
5297   SALOMEDS::GenericAttribute_var    anAttr;
5298   SALOMEDS::AttributeName_var       aName;
5299   SALOMEDS::AttributePixMap_var     aPixmap;
5300   SALOMEDS::AttributeIOR_var        anIOR;
5301   SALOMEDS::AttributeSelectable_var aSelAttr;
5302   
5303   SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
5304   int aLocked = false;
5305   if (father->_is_nil()) {
5306     QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5307     op->start();
5308     aLocked = aStudy->GetProperties()->IsLocked();
5309     if (aLocked) aStudy->GetProperties()->SetLocked(false);
5310     father = aStudyBuilder->NewComponent("GEOM");
5311     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
5312     aName = SALOMEDS::AttributeName::_narrow(anAttr);
5313     //    aName->SetValue( tr("GEOM_MEN_COMPONENT") );
5314     aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) );
5315     anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
5316     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
5317     aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
5318     if (aLocked) aStudy->GetProperties()->SetLocked(true);
5319     op->finish();
5320   }
5321 //    if (aLocked) return false;
5322
5323   aStudyBuilder->DefineComponentInstance( father, myComponentGeom );
5324   father->ComponentIOR( Fatherior );
5325   
5326   SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(myActiveStudy->getActiveStudyFrame()->entry());
5327   
5328   Handle(GEOM_AISShape) GAISShape;
5329   GEOM_Actor* GActor;
5330   Handle(GEOM_InteractiveObject) GIO;
5331   bool found = false;
5332
5333   // VTK
5334   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5335     vtkRenderer *Renderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5336
5337     vtkActorCollection* theActors = Renderer->GetActors();
5338     theActors->InitTraversal();
5339     vtkActor *ac = theActors->GetNextActor();
5340     while(!(ac==NULL)) {
5341       if ( ac->IsA("GEOM_Actor") ) {
5342         GEOM_Actor* anActor = GEOM_Actor::SafeDownCast( ac );
5343         if ( anActor->hasIO() ) {
5344           Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5345           if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
5346             GIO = Handle(GEOM_InteractiveObject)::DownCast( IO );
5347             if ( anIO->isSame( GIO ) ) {
5348               found = true;
5349               GActor = anActor;
5350               break;
5351             }
5352           }
5353         }
5354       }
5355       ac = theActors->GetNextActor();
5356     }
5357     
5358     if ( !found )
5359       return false;
5360   }
5361   // OCC
5362   else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC )  {
5363     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
5364     Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5365     
5366     AIS_ListOfInteractive List;
5367     ic->DisplayedObjects(List);
5368     AIS_ListIteratorOfListOfInteractive ite(List);
5369     while (ite.More()) {
5370       if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
5371         Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
5372         if ( aSh->hasIO() ) {
5373           Handle(SALOME_InteractiveObject) IO = aSh->getIO();
5374           if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
5375             GIO = Handle(GEOM_InteractiveObject)::DownCast( IO );
5376             if ( anIO->isSame( GIO ) ) {
5377               found = true;
5378               GAISShape = aSh;
5379               break;
5380             }
5381           }
5382         }
5383       }
5384       ite.Next();
5385     }
5386
5387     if ( !found )
5388       return false;
5389   }
5390
5391   if ( !Settings_AddInStudy || selection ) {
5392     QString Name = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), anIO->getName() );
5393     if ( !Name.isEmpty() ) {
5394       // VTK
5395       if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5396         GActor->setName( strdup(Name.latin1()) );
5397       }
5398       // OCC
5399       else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5400         GAISShape->setName( strdup(Name.latin1()) );
5401       }
5402     } else {
5403       return false;
5404     }
5405   }
5406
5407   // open transaction
5408   QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5409   op->start();
5410
5411   SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
5412
5413   GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( GIO->getIOR() );
5414
5415   /* For the shape inserted into the study we set its field 'studyshapeid'    */
5416   /* so the shape will contain its corresponding entry in the study Ocaf doc. */
5417   aShape->StudyShapeId(newObj->GetID()) ;
5418
5419   GIO->setEntry(newObj->GetID());
5420
5421   anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
5422   anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5423   anIOR->SetValue(aShape->Name());
5424
5425   anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
5426   aName = SALOMEDS::AttributeName::_narrow(anAttr);
5427
5428   anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
5429   aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
5430   if ( aShape->ShapeType() == GEOM::COMPOUND ) {
5431     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
5432   } else if ( aShape->ShapeType() == GEOM::COMPSOLID ) {
5433     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
5434   } else if ( aShape->ShapeType() == GEOM::SOLID ) {
5435     aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
5436   } else if ( aShape->ShapeType() == GEOM::SHELL ) {
5437     aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
5438   } else if ( aShape->ShapeType() == GEOM::FACE ) {
5439     aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
5440   } else if ( aShape->ShapeType() == GEOM::WIRE ) {
5441     aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
5442   } else if ( aShape->ShapeType() == GEOM::EDGE ) {
5443     aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
5444   } else if ( aShape->ShapeType() == GEOM::VERTEX ) {
5445     aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
5446   }
5447
5448   // VTK
5449   if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5450     GActor->setIO( GIO );
5451     aName->SetValue(GActor->getName());
5452   }
5453   // OCC
5454   else if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5455     GAISShape->setIO( GIO );
5456     aName->SetValue(GAISShape->getName());
5457   }
5458
5459   SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
5460   aStudyBuilder->Addreference(newObj1,newObj);
5461
5462   GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
5463   listIOR = myComponentGeom->GetReferencedObjects(aShape);
5464
5465   if (listIOR->length()>0) {
5466     SALOMEDS::SObject_var Arguments = aStudyBuilder->NewObject(newObj);
5467     anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeName");
5468     aName = SALOMEDS::AttributeName::_narrow(anAttr);
5469     aName->SetValue(tr("GEOM_ARGUMENTS"));
5470     anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeSelectable");
5471     aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
5472     aSelAttr->SetSelectable(false);
5473
5474     bool ObjectReferenced = false;
5475     for (unsigned int ind = 0; ind < listIOR->length();ind++) {
5476       SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(listIOR[ind]);
5477
5478       if ( !theObj->_is_nil() ) {
5479         SALOMEDS::SObject_var RefObject = aStudyBuilder->NewObject(Arguments);
5480         aStudyBuilder->Addreference(RefObject, theObj);
5481         ObjectReferenced = true;
5482       }
5483     }
5484
5485     if ( !ObjectReferenced )
5486       aStudyBuilder->RemoveObject(Arguments);
5487   }
5488
5489   op->finish();
5490
5491
5492   if ( !Settings_AddInStudy || selection ) {
5493     myActiveStudy->updateObjBrowser();
5494   } else {
5495     myActiveStudy->updateObjBrowser(false);
5496     Sel->AddIObject( GIO );
5497   }
5498
5499   // MESSAGE ( " highlihght done" )
5500   return true;
5501  
5502 }
5503
5504
5505 //=====================================================================================
5506 // function : GetShapeFromIOR()
5507 // purpose  : exist also as static method !
5508 //=====================================================================================
5509 TopoDS_Shape GeometryGUI::GetShapeFromIOR( QString IOR )
5510 {
5511   TopoDS_Shape result;
5512   if( IOR.stripWhiteSpace().isEmpty() )
5513     return result;
5514   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
5515   CORBA::ORB_var& _orb = init.orb() ;
5516   CORBA::Object_var obj = _orb->string_to_object( (char*)(IOR.latin1()) );
5517   if ( CORBA::is_nil( obj ) )
5518     return result;
5519   GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( IOR );
5520   if (!aShape->_is_nil()) {
5521     result = ShapeReader.GetShape( myComponentGeom, aShape );
5522   }
5523   return result;
5524 }
5525
5526
5527 //=====================================================================================
5528 // function : SetSettings()
5529 // purpose  : [static]
5530 //=====================================================================================
5531 bool GeometryGUI::SetSettings( QAD_Desktop* parent )
5532 {
5533   /* Create or retrieve an object GeomGUI */
5534   GeometryGUI::GetOrCreateGeometryGUI(parent);
5535
5536   //DCQ  parent->menuBar()->setItemEnabled( 504, false);  // CORRECTING
5537   //DCQ  parent->menuBar()->setItemEnabled( 6062, false); // RADIUS
5538   //VSR  parent->menuBar()->setItemEnabled( 701, false);  // AUTOMATIC COPY
5539   parent->menuBar()->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
5540   parent->menuBar()->setItemEnabled( 3131, false); // SKETCH SET PLAN
5541
5542   /* Shading Color */
5543   QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed");
5544   QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen");
5545   QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue");
5546   if( !SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty() )   
5547     GeomGUI->myShadingColor = Quantity_Color ( SCr.toInt()/255., SCg.toInt()/255., SCb.toInt()/255.,
5548                                                Quantity_TOC_RGB );
5549
5550   /* Wireframe or Shading */
5551   int DisplayMode = 0;
5552   if ( parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
5553     OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
5554     Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
5555     DisplayMode = ic->DisplayMode();
5556   } else if ( parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
5557     VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5558     DisplayMode = myRenderInter->GetDisplayMode();
5559   }
5560
5561   if ( DisplayMode == 1 )
5562     parent->menuBar()->changeItem(6021, tr("GEOM_MEN_WIREFRAME") );
5563   else
5564     parent->menuBar()->changeItem(6021, tr("GEOM_MEN_SHADING") );
5565
5566   /* Copy */
5567 //    QString Copy = QAD_CONFIG->getSetting("Geometry:SettingsCopy");
5568 //    if ( !Copy.isEmpty() ) {
5569 //      Settings_Copy = Copy.toInt();
5570 //      QMenuData* pp;
5571 //      parent->menuBar()->findItem(701,&pp);
5572 //      pp->setItemChecked(701, Settings_Copy);
5573 //    }
5574  QMenuData* pp;
5575  if ( parent->menuBar()->findItem(701,&pp) )
5576    pp->removeItem(701);
5577
5578   /* Add in Study */
5579   QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
5580   if ( !AddInStudy.isEmpty() )
5581     Settings_AddInStudy  = AddInStudy.toInt();
5582   else
5583     Settings_AddInStudy = 1;
5584   parent->menuBar()->findItem(702,&pp);
5585   pp->setItemChecked(702, Settings_AddInStudy);
5586
5587   /* step value */
5588   QString S = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" );
5589   if( S.isEmpty() )
5590     QAD_CONFIG->addSetting( "Geometry:SettingsGeomStep", "100" );
5591   
5592   /* isos */
5593   QAD_Study* ActiveStudy = parent->getActiveStudy();
5594   int count = ActiveStudy->getStudyFramesCount();
5595
5596   bool ViewOCC = false;
5597   for ( int i = 0; i < count; i++ ) {
5598     if ( ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC ) {
5599       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
5600       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5601       
5602       QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
5603       QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
5604       if ( !IsoU.isEmpty() )
5605         ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
5606       if ( !IsoV.isEmpty() )
5607         ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
5608
5609       ViewOCC = true;
5610     }
5611   }
5612
5613   QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
5614
5615   Mb->setItemEnabled( 312, ViewOCC); //Sketch
5616   Mb->setItemEnabled( 309, ViewOCC); //SuppressFace
5617   Mb->setItemEnabled( 314, ViewOCC); //SuppressHole
5618   
5619   Mb->setItemEnabled( 703, ViewOCC);// ShadingColor Settings
5620   Mb->setItemEnabled( 704, ViewOCC);// Isos Settings
5621
5622   return true;
5623 }
5624
5625
5626 //=====================================================================================
5627 // function : DefinePopup()
5628 // purpose  : [static]
5629 //=====================================================================================
5630 void GeometryGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
5631 {
5632   /* Create or retrieve an object GeomGUI */
5633   GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
5634   SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
5635
5636   theObject = "";
5637   if ( Sel->IObjectCount() == 1 ) 
5638     {
5639       Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
5640       if (IO->hasEntry())
5641         {
5642           SALOMEDS::SObject_var sobj = GeomGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
5643           if (!sobj->_is_nil()) 
5644             {
5645               SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
5646               if (strcmp(scomp->GetID(), IO->getEntry()) == 0) 
5647                 { 
5648                   // component is selected
5649                   theObject = "Component";
5650                 }
5651             }
5652         }
5653     }
5654
5655   if ( ( theParent.compare("Viewer")==0 ) ) 
5656     {
5657       if ( GeomGUI->myState == CURRENT_SKETCH ) 
5658         theContext = "Sketch";
5659       else 
5660         {
5661           if ( Sel->IObjectCount() > 0 )
5662             theContext = "";
5663           else
5664             theContext = "NothingSelected";
5665         }
5666     } 
5667   else 
5668     theContext = "";
5669   
5670 }
5671
5672 //=====================================================================================
5673 // function : CustomPopup()
5674 // purpose  : [static]
5675 //=====================================================================================
5676 bool GeometryGUI::CustomPopup( QAD_Desktop* parent,
5677                                QPopupMenu* popup,
5678                                const QString& theContext,
5679                                const QString& theParent,
5680                                const QString& theObject )
5681 {
5682   /* Create or retrieve an object GeomGUI */
5683   GeometryGUI::GetOrCreateGeometryGUI(parent);
5684   
5685   /* Deactivate any non modal dialog box to get the neutral point */
5686   GeomGUI->EmitSignalDeactivateDialog() ;
5687   
5688   SALOME_Selection* Sel = SALOME_Selection::Selection( GeomGUI->myActiveStudy->getSelection() );
5689   int nbSel = Sel->IObjectCount();
5690   
5691   if ( (nbSel == 0) && ( theContext.compare("Sketch")!=0 ) )
5692     return false;
5693   
5694     
5695   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
5696     {
5697       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->
5698                                  getRightFrame()->getViewFrame())->getViewer();
5699       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
5700       if ( theParent.compare("Viewer")==0 )
5701         {
5702           if ( theContext.compare("Sketch")==0 )
5703             {
5704               SketchStatus myCS = GeomGUI->mySketcher.GetCurrentStatus();
5705               popup->setCheckable(TRUE);
5706               if (myCS==SEGMENT) 
5707                 {
5708                   popup->setItemChecked(10000,true);
5709                   popup->setItemChecked(10001,false);
5710                 }
5711               else if (myCS==ARC_CHORD)
5712                 {
5713                   popup->setItemChecked(10000,false);
5714                   popup->setItemChecked(10001,true);
5715                 }
5716               
5717               return true;
5718             }
5719           else
5720             if (theObject.compare("Component") == 0)
5721               {
5722                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
5723                 return true;
5724               }
5725             else
5726               {
5727                 QFont f = QApplication::font();
5728                 f.setBold( TRUE );
5729                 if (nbSel==1)
5730                   {
5731                     Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5732                     popup->removeItem(QAD_TopLabel_Popup_ID);
5733                     popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), QAD_TopLabel_Popup_ID, 0 );
5734                     if ( IObject->hasEntry() )
5735                       popup->setItemEnabled( 801, false );
5736                     else
5737                       popup->setItemEnabled( 801, true );
5738                     
5739                     if (IObject->IsKind(STANDARD_TYPE(GEOM_InteractiveObject)))
5740                       {
5741                         Standard_Boolean found;
5742                         Handle(GEOM_AISShape) Result = GeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
5743
5744                         if ( found )
5745                           {
5746                             if ( Result->DisplayMode() == 1 )
5747                               popup->changeItem(8021, tr("GEOM_MEN_WIREFRAME") );
5748                             else
5749                               popup->changeItem(8021, tr("GEOM_MEN_SHADING") );
5750                           }
5751                       }
5752
5753                     if ( !(v3d->isInViewer( IObject ) && v3d->isVisible( IObject )) )
5754                       popup->removeItem(QAD_Erase_Popup_ID);
5755                     else
5756                       popup->removeItem(QAD_Display_Popup_ID);
5757                     
5758                   }
5759                 else
5760                   {
5761                     popup->removeItem(QAD_DisplayOnly_Popup_ID);
5762                     popup->removeItem(QAD_TopLabel_Popup_ID);
5763                     popup->insertItem( new CustomItem ( tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f ),
5764                                       QAD_TopLabel_Popup_ID, 0 );
5765                     popup->setItemEnabled( 801, false );
5766                   }
5767               }
5768           return true;
5769         }
5770       else
5771         if ( theParent.compare("ObjectBrowser")==0 )
5772           {
5773             popup->removeItem(QAD_TopLabel_Popup_ID);
5774             int id = popup->idAt(0); // separator
5775             if (id < 0) popup->removeItem(id);
5776             
5777             // checking for GEOM label in the selected list
5778             SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5779             Handle(SALOME_InteractiveObject) anIObject;
5780
5781             bool useSubItems = false;
5782             bool needOpen = false;
5783             bool needDisplay = false;
5784             bool needErase = false;
5785             SALOMEDS::GenericAttribute_var aTmpAttr;
5786             for(;It.More();It.Next())
5787               {
5788                 anIObject = It.Value();
5789                 if (!anIObject->hasEntry())
5790                     continue;
5791                 
5792                 if (v3d->isInViewer(anIObject) && v3d->isVisible(anIObject)) 
5793                   needErase = true; 
5794                 else 
5795                   needDisplay = true;
5796                 SALOMEDS::SObject_var obj =
5797                   GeomGUI->myActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
5798                 if (!obj->_is_nil())
5799                   {
5800                     GEOM::GEOM_Shape_var aShape;
5801                     if (obj->FindAttribute(aTmpAttr, "AttributeIOR")) {
5802                       char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
5803                       if (str && strlen(str))
5804                         aShape = GeomGUI->myComponentGeom-> GetIORFromString(str);
5805                     }
5806                     else
5807                       if (obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5808                         needOpen = true;
5809                     if (aShape->_is_nil())
5810                       {
5811                         SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->
5812                           getStudyDocument()->NewChildIterator(obj);
5813                         while (anIter->More())
5814                           {
5815                             SALOMEDS::SObject_var subobj = anIter->Value();
5816                             if (subobj->FindAttribute(aTmpAttr, "AttributeIOR"))
5817                               {
5818                                 useSubItems = true;
5819                                 needErase = true;
5820                                 needDisplay = true;
5821                               }
5822                             else
5823                               if (subobj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5824                                 {
5825                                   needOpen = true;
5826                                   useSubItems = true;
5827                                 }
5828                             anIter->Next();
5829                           }
5830                       }
5831                   }
5832               }
5833             // remove useless popup items
5834             if (nbSel != 1) popup->removeItem(901); // rename
5835             if (useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
5836             if (!needOpen)
5837               {
5838                 int index = popup->indexOf(9024);
5839                 popup->removeItem(9024); // open
5840                 popup->removeItemAt(index); // separator under Open
5841
5842                 if (!needDisplay) popup->removeItem(QAD_Display_Popup_ID);
5843                 if (!needErase) popup->removeItem(QAD_Erase_Popup_ID);
5844                 if (!needDisplay && !needErase)
5845                   {
5846                     int id = popup->idAt(popup->count()-1); // last item
5847                     popup->removeItem(id); // separator
5848                   }
5849               }
5850             else
5851               {
5852                 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
5853                 popup->removeItem(QAD_Display_Popup_ID);
5854                 popup->removeItem(QAD_Erase_Popup_ID);
5855                 if (nbSel!=1)
5856                   {
5857                     int id = popup->idAt(popup->count()-1); // last item
5858                     popup->removeItem(id); // separator
5859                   }
5860               }
5861             return true;
5862           }
5863       // MESSAGE ( " CUSTOM POPUP VIEWER OCC done. ")
5864     }
5865   else
5866     if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
5867       {
5868         // MESSAGE ( " CUSTOM POPUP VIEWER VTK ")
5869         if ( ( theParent.compare("Viewer")==0 ) )
5870           {
5871             
5872             popup->setItemEnabled( 8033, false );
5873             if (theObject.compare("Component") == 0)
5874               {
5875                 popup->removeItem(QAD_DisplayOnly_Popup_ID);
5876                 return true;
5877               } 
5878
5879           //int id = popup->idAt(0);
5880           QFont f = QApplication::font();
5881           f.setBold( TRUE );
5882           
5883           if (nbSel==1)
5884             {
5885               Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5886               popup->removeItem(QAD_TopLabel_Popup_ID);
5887               popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), QAD_TopLabel_Popup_ID, 0 );
5888               if ( IObject->hasEntry() )
5889                 {
5890                   popup->setItemEnabled( 801, false );
5891                   SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
5892                   SALOMEDS::SObject_var SO = aStudy->FindObjectID( IObject->getEntry() );
5893                   SALOMEDS::GenericAttribute_var anAttr;
5894                   SALOMEDS::AttributeIOR_var     anIOR;
5895                   if ( !SO->_is_nil() )
5896                     {
5897                       if (SO->FindAttribute(anAttr, "AttributeIOR") )
5898                         {
5899                           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5900                           Standard_Boolean found;
5901                           GEOM_Actor* Result = GeomGUI->ConvertIORinGEOMActor(anIOR->Value(), found, true);
5902                           if ( found )
5903                             {
5904                               if ( Result->getDisplayMode() == 1 )
5905                                 popup->changeItem(8021, "Wireframe" );
5906                               else
5907                                 popup->changeItem(8021, "Shading" );
5908                               
5909                               if ( !Result->GetVisibility() )
5910                                 popup->removeItem(QAD_Erase_Popup_ID);
5911                               else
5912                                 popup->removeItem(QAD_Display_Popup_ID);                  
5913                             }
5914                           else
5915                             popup->removeItem(QAD_Erase_Popup_ID);
5916                         }
5917                     }
5918                 }
5919               else
5920                 popup->setItemEnabled( 801, true );
5921             }
5922           else
5923             {
5924               popup->removeItem(QAD_DisplayOnly_Popup_ID);
5925               popup->removeItem(QAD_TopLabel_Popup_ID);
5926               popup->insertItem( new CustomItem ( tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f ), QAD_TopLabel_Popup_ID, 0 );
5927               popup->setItemEnabled( 801, false );
5928             }
5929           return true;
5930         }
5931         else
5932           if ( theParent.compare("ObjectBrowser")==0 )
5933             {
5934               popup->removeItem(QAD_TopLabel_Popup_ID);
5935               int id = popup->idAt(0); // separator
5936               if (id < 0) popup->removeItem(id);
5937       
5938               // checking for GEOM label in the selected list
5939               SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5940               Handle(SALOME_InteractiveObject) anIObject;
5941               
5942               bool useSubItems = false;
5943               bool needOpen = false;
5944               bool needDisplay = false;
5945               bool needErase = false;
5946               SALOMEDS::GenericAttribute_var aTmpAttr;
5947               VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->
5948                                                getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5949               for(;It.More();It.Next())
5950                 {
5951                   anIObject = It.Value();
5952                   if ( !anIObject->hasEntry() )
5953                     continue;
5954                   
5955                   if (myRenderInter->isInViewer(anIObject) && myRenderInter->isVisible(anIObject)) 
5956                     needErase = true; 
5957                   else 
5958                     needDisplay = true;
5959
5960                   SALOMEDS::SObject_var obj = GeomGUI->myActiveStudy->getStudyDocument()
5961                     ->FindObjectID( anIObject->getEntry() );
5962                   if (!obj->_is_nil()) {
5963                     GEOM::GEOM_Shape_var aShape;
5964                     if (obj->FindAttribute(aTmpAttr, "AttributeIOR")){
5965                       char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
5966                       if (str && strlen(str))
5967                         aShape = GeomGUI->myComponentGeom->GetIORFromString(str);
5968                     }
5969                     else
5970                       if (obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5971                         needOpen = true;
5972                     if (aShape->_is_nil())
5973                       {
5974                         SALOMEDS::ChildIterator_var anIter =
5975                           GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
5976                         while (anIter->More())
5977                           {
5978                             SALOMEDS::SObject_var subobj = anIter->Value();
5979                             if (subobj->FindAttribute(aTmpAttr, "AttributeIOR"))
5980                               {
5981                                 useSubItems = true;
5982                                 needDisplay = true;
5983                                 needErase = true;
5984                               }
5985                             else
5986                               if (subobj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
5987                                 {
5988                                   needOpen = true;
5989                                   useSubItems = true;
5990                                 }
5991                             anIter->Next();
5992                           }
5993                       }
5994                   }
5995                 }
5996               // remove useless popup items
5997               if (nbSel != 1) popup->removeItem(901); // rename
5998               if (useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
5999               if (!needOpen)
6000                 {
6001                   int index = popup->indexOf(9024);
6002                   popup->removeItem(9024); // open
6003                   popup->removeItemAt(index); // separator under Open
6004                   
6005                   if (!needDisplay) popup->removeItem(QAD_Display_Popup_ID);
6006                   if (!needErase) popup->removeItem(QAD_Erase_Popup_ID);
6007                   if (!needDisplay && !needErase)
6008                     {
6009                       int id = popup->idAt(popup->count()-1); // last item
6010                       popup->removeItem(id); // separator
6011                     }
6012                 }
6013               else
6014                 {
6015                   popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
6016                   popup->removeItem(QAD_Display_Popup_ID);
6017                   popup->removeItem(QAD_Erase_Popup_ID);
6018                   if (nbSel!=1)
6019                     {
6020                       int id = popup->idAt(popup->count()-1); // last item
6021                       popup->removeItem(id); // separator
6022                     }
6023                 }
6024               return true;
6025               // MESSAGE ( " CUSTOM POPUP VIEWER VTK done.")
6026             }
6027       } else
6028         { // other viewer types not supported.
6029           while (1)
6030             {
6031               int id = popup->idAt(0);
6032               if (id <= QAD_TopLabel_Popup_ID && id != -1)
6033                 popup->removeItemAt(0);
6034               else
6035                 break;
6036             }
6037           popup->removeItem(QAD_DisplayOnly_Popup_ID);  
6038           popup->removeItem(QAD_Display_Popup_ID);
6039           popup->removeItem(QAD_Erase_Popup_ID);
6040           int id = popup->idAt(popup->count()-1); // last item
6041           if (id < 0 && id != -1) popup->removeItem(id); // separator
6042           return false;
6043         }
6044   return false;
6045 }
6046
6047 void GeometryGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
6048 {
6049   /* Create or retrieve an object GeomGUI */
6050   GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
6051   
6052   SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
6053   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
6054   
6055   OCCViewer_Viewer3d* v3d;
6056   Handle(AIS_InteractiveContext) ic;
6057   vtkRenderer* Renderer;
6058
6059   if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
6060     v3d = ((OCCViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6061     ic = v3d->getAISContext();
6062   } else if ( GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
6063     Renderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6064   } else
6065     return;
6066
6067   if (theIO.IsNull())
6068     MESSAGE("BuildPresentation(): null SALOME_InteractiveObject passed")
6069
6070   if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
6071     // VTK
6072           
6073     SALOMEDS::SObject_var fatherSF = 
6074       aStudy->FindObjectID(GeomGUI->myActiveStudy->getActiveStudyFrame()->entry());
6075             
6076     SALOMEDS::SObject_var obj = aStudy->FindObjectID( theIO->getEntry() );
6077
6078     VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
6079
6080     SALOMEDS::GenericAttribute_var anAttr;
6081     SALOMEDS::AttributeName_var    aName;
6082     SALOMEDS::AttributeIOR_var     anIOR;
6083          
6084     if(myRenderInter->isInViewer(theIO)) {
6085       myRenderInter->Display(theIO, false);
6086     }
6087     else {
6088       // Create new actor
6089       if ( !obj->_is_nil() ) {
6090         if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
6091           // this SObject may be GEOM module root SObject
6092
6093           bool useSubItems = false;
6094           SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
6095           if (GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
6096             while (anIter->More() && !useSubItems) {
6097               SALOMEDS::SObject_var subobj = anIter->Value();
6098               SALOMEDS::GenericAttribute_var aTmpAttr;
6099               if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
6100                 if (!GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
6101                   anAttr = aTmpAttr;
6102                   obj = subobj;
6103                   useSubItems = true;
6104                 } else anIter->Next();
6105               } else anIter->Next();
6106             }
6107           }
6108
6109           while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
6110             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6111             GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
6112             TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
6113             
6114             if (obj->FindAttribute(anAttr, "AttributeName")) {
6115               aName = SALOMEDS::AttributeName::_narrow(anAttr);
6116               
6117               vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6118               vtkActorCollection* theAllActors = theRenderer->GetActors();
6119               theAllActors->InitTraversal();
6120               vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
6121               Handle(SALOME_InteractiveObject) anIObj;
6122               // don't create new study object if it already exists
6123               bool isDisplayed = false;
6124               while(!(actor==NULL)) {
6125                 SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
6126                 if (Gactor!=NULL) {
6127                   if (Gactor->hasIO()) {
6128                     if (strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
6129                       isDisplayed = true;
6130                       anIObj = Gactor->getIO();
6131                       if (!anIObj.IsNull()) myRenderInter->Display(anIObj, false);
6132                     }
6133                   }
6134                 }
6135                 actor=(vtkActor*)(theAllActors->GetNextActor());
6136               }
6137               if (!isDisplayed) {
6138                 // open transaction
6139                 QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy );
6140                 op->start();
6141                 
6142                 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
6143                 aStudyBuilder->Addreference(newObj1, obj);
6144                 // commit transaction
6145                 op->finish();
6146                 
6147                 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6148                 int themode = myRenderInter->GetDisplayMode();
6149                 
6150                 vtkActorCollection* theActors = 
6151                   GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
6152                 theActors->InitTraversal();
6153                 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
6154                 while(!(anActor==NULL)) {
6155                   GEOM_Actor* GActor = GEOM_Actor::SafeDownCast( anActor );
6156                   Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), Fatherior,"GEOM");
6157                   IO->setEntry(obj->GetID());
6158                   GActor->setIO( IO );
6159                   GActor->setName( theIO->getName() );
6160                   
6161                   theRenderer->AddActor(GActor);
6162                   //              renWin->Render();
6163                   anActor = (vtkActor*)theActors->GetNextActor();
6164                 }
6165               }
6166             }
6167             // next item iteration
6168             if (useSubItems) {
6169               anIter->Next();
6170               anAttr = SALOMEDS::GenericAttribute::_nil();
6171               while (anIter->More() && anAttr->_is_nil()) {
6172                 SALOMEDS::SObject_var subobject = anIter->Value();
6173                 SALOMEDS::GenericAttribute_var aTmpAttribute;
6174                 if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
6175                   anAttr = aTmpAttribute;
6176                   obj = subobject;
6177                 } else anIter->Next();
6178               }
6179             } else anAttr = SALOMEDS::GenericAttribute::_nil();
6180           }
6181         }
6182       }
6183     }
6184     // No viewer update should be done here!
6185     //myRenderInter->Render();
6186     //GeomGUI->myActiveStudy->updateObjBrowser( true );
6187   } else if (GeomGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
6188     SALOMEDS::SObject_var fatherSF = 
6189       aStudy->FindObjectID( GeomGUI->myActiveStudy->getActiveStudyFrame()->entry());
6190     SALOMEDS::GenericAttribute_var anAttr;
6191     SALOMEDS::AttributeName_var    aName;
6192     SALOMEDS::AttributeIOR_var     anIOR;
6193
6194     if ( v3d->isInViewer( theIO, true ) ) {
6195       Standard_Boolean found;
6196       Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape( theIO, found, true );
6197       if ( found ) {
6198         ic->Display(aSh, false);
6199         ic->AddOrRemoveCurrentObject(aSh, false);
6200       }
6201       
6202     } else {
6203       SALOMEDS::SObject_var obj = aStudy->FindObjectID( theIO->getEntry() );          
6204       if ( !obj->_is_nil() ) {
6205         MESSAGE("BuildPresentation(): SObject not null")
6206         if ( obj->FindAttribute(anAttr, "AttributeIOR")) {
6207           MESSAGE("BuildPresentation(): SObject has IOR")
6208           // this SObject may be GEOM module root SObject
6209
6210           bool useSubItems = false;
6211           SALOMEDS::ChildIterator_var anIter = GeomGUI->myActiveStudy->getStudyDocument()->NewChildIterator(obj);
6212           if (GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
6213             while (anIter->More() && !useSubItems) {
6214               SALOMEDS::SObject_var subobj = anIter->Value();
6215               SALOMEDS::GenericAttribute_var aTmpAttr;
6216               if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
6217                 if (!GeomGUI->myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
6218                   anAttr = aTmpAttr;
6219                   obj = subobj;
6220                   useSubItems = true;
6221                 } else anIter->Next();
6222               } else anIter->Next();
6223             }
6224           }
6225
6226           while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
6227             anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6228             GEOM::GEOM_Shape_var aShape = GeomGUI->myComponentGeom->GetIORFromString(anIOR->Value());
6229             TopoDS_Shape Shape = ShapeReader.GetShape(GeomGUI->myComponentGeom,aShape);
6230             if (Shape.IsNull())
6231               MESSAGE("BuildPresentation(): TopoDS_Shape is null!")
6232             if (obj->FindAttribute(anAttr, "AttributeName")) {
6233               MESSAGE("BuildPresentation(): SObject has Name")
6234               aName = SALOMEDS::AttributeName::_narrow(anAttr);
6235               // searchin for already displayed objects with the same shape
6236               AIS_ListOfInteractive aDisplayed;
6237               ic->DisplayedObjects(aDisplayed);
6238               AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
6239               Handle(AIS_Shape) anAISShape;
6240               for(;anIObjects.More();anIObjects.Next()) {
6241                 anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
6242                 if (!anAISShape.IsNull()) {
6243                   if (anAISShape->Shape().IsSame(Shape)) break;
6244                   anAISShape.Nullify();
6245                 }
6246               }
6247               if (!anAISShape.IsNull()) {
6248                 if (!ic->IsDisplayed(anAISShape)) ic->Display(anAISShape, false);
6249               } else {
6250                 if (!useSubItems) {
6251                   // open transaction
6252                   QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->myActiveStudy );
6253                   op->start();
6254                   if (fatherSF->_is_nil())
6255                     MESSAGE("BuildPresentation(): fatherSF is nil!")
6256                   SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
6257                   aStudyBuilder->Addreference(newObj1, obj);
6258                   // commit transaction
6259                   op->finish();
6260                 }
6261                 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
6262                 aSh->SetShadingColor( GeomGUI->myShadingColor );
6263                 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(),
6264                                                                                Fatherior,
6265                                                                                "GEOM");
6266                 IO->setEntry(obj->GetID());
6267                 aSh->setIO( IO );
6268                 aSh->setName( aName->Value() );
6269                 ic->Display (aSh, false);
6270                 if (!useSubItems) ic->AddOrRemoveCurrentObject(aSh, false);
6271               }
6272             }
6273             // next item iteration
6274             if (useSubItems) {
6275               anIter->Next();
6276               anAttr=SALOMEDS::GenericAttribute::_nil();
6277               while (anIter->More() && anAttr->_is_nil()) {
6278                 SALOMEDS::SObject_var subobject = anIter->Value();
6279                 SALOMEDS::GenericAttribute_var aTmpAttribute;
6280                 if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
6281                   anAttr = aTmpAttribute;
6282                   obj = subobject;
6283                 } else anIter->Next();
6284               }
6285             } else 
6286               anAttr = SALOMEDS::GenericAttribute::_nil();
6287           }
6288         }
6289       }
6290     }
6291     // No viewer update should be done here!
6292     //GeomGUI->myActiveStudy->updateObjBrowser( true );
6293     //ic->UpdateCurrentViewer();
6294   }
6295 }
6296
6297 //=======================================================================
6298 // function : Parameter()
6299 // purpose  : return a parameter (float) from a dialog box
6300 //
6301 //  avalue1    : is a float or integer used as a default value displayed
6302 //  aTitle1    : is the title for aValue1
6303 //  aTitle     : is the main title
6304 //  bottom     : maximum value to be entered
6305 //  top        : minimum value to be entered
6306 //  decimals   : number of decimals
6307 //=======================================================================
6308 double GeometryGUI::Parameter( Standard_Boolean& res,
6309                                const char* aValue1,
6310                                const char* aTitle1,
6311                                const char* aTitle,
6312                                const double bottom,
6313                                const double top,
6314                                const int decimals )
6315 {
6316   GeometryGUI_aParameterDlg * Dialog =
6317     new GeometryGUI_aParameterDlg(aValue1,
6318                                   aTitle1,
6319                                   QAD_Application::getDesktop(),
6320                                   aTitle,
6321                                   TRUE,
6322                                   0,
6323                                   bottom,
6324                                   top,
6325                                   decimals) ;
6326   int r = Dialog->exec() ;
6327   float X = 0.0 ;
6328   if ( r == QDialog::Accepted ) {
6329     res = Standard_True;
6330     X = Dialog->getValue();
6331   } else
6332     res = Standard_False;
6333   delete Dialog;
6334   return X;
6335 }
6336
6337
6338 //=======================================================================
6339 // function : OnSketchSegment()
6340 // purpose  : 
6341 //=======================================================================
6342 void GeometryGUI::OnSketchSegment()
6343 {
6344   this->mySketcher.ChangeMode(SEGMENT);
6345 }
6346
6347
6348 //=======================================================================
6349 // function : OnSketchArc()
6350 // purpose  : 
6351 //=======================================================================
6352 void GeometryGUI::OnSketchArc()
6353 {
6354   this->mySketcher.ChangeMode(ARC_CHORD);
6355 }
6356
6357 //=======================================================================
6358 // function : OnSketchSetAngle()
6359 // purpose  : 
6360 //=======================================================================
6361 void GeometryGUI::OnSketchSetAngle()
6362 {
6363   Standard_Real anAngle = this->mySketcher.GetSegmentAngle()/PI180;
6364   Sketch::fitInResol(anAngle); 
6365   Standard_Boolean res = false ;
6366   QString Value = QString("%1").arg( anAngle );
6367   anAngle = Parameter(res, Value, tr("GEOM_MEN_ANGLE"), tr("GEOM_MEN_ENTER_ANGLE"), -180.0, +180.0, 6 )*PI180 ;
6368
6369   if( res ) {
6370     this->mySketcher.SetSegmentAngle(anAngle);
6371     QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6372     QMenuData* pp;
6373     QMenuItem* item = Mb->findItem(3133,&pp);
6374     pp->setItemChecked(3133,false);
6375     item = Mb->findItem(3134,&pp);
6376     pp->setItemChecked(3134,false);
6377   }
6378   
6379 }
6380
6381
6382 //=======================================================================
6383 // function : OnSketchSetx()
6384 // purpose  : 
6385 //=======================================================================
6386 void GeometryGUI::OnSketchSetx()
6387 {
6388   Standard_Boolean res = false;
6389   double X = Parameter( res,
6390                         "0.",
6391                         tr("GEOM_MEN_X"),
6392                         tr("GEOM_MEN_SKETCHER_X"),
6393                         2.0 * Precision::Confusion(),
6394                         1E6,
6395                         6 ) ;
6396   if (res)
6397     this->mySketcher.SetXDimension(X);
6398   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6399   QMenuData* pp;
6400   QMenuItem* item = Mb->findItem(3133,&pp);
6401   pp->setItemChecked(3133,false);
6402   item = Mb->findItem(3134,&pp);
6403   pp->setItemChecked(3134,false);
6404 }
6405
6406 //=======================================================================
6407 // function : OnSketchSety()
6408 // purpose  : 
6409 //=======================================================================
6410 void GeometryGUI::OnSketchSety()
6411 {
6412   Standard_Boolean res = false;
6413   double Y = Parameter( res,
6414                         "0.",
6415                         tr("GEOM_MEN_Y"),
6416                         tr("GEOM_MEN_SKETCHER_Y"),
6417                         2.0 * Precision::Confusion(),
6418                         1E6,
6419                         6 ) ;
6420   if (res)
6421     this->mySketcher.SetYDimension(Y);
6422   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6423   QMenuData* pp;
6424   QMenuItem* item = Mb->findItem(3133,&pp);
6425   pp->setItemChecked(3133,false);
6426   item = Mb->findItem(3134,&pp);
6427   pp->setItemChecked(3134,false);
6428 }
6429
6430
6431 //=======================================================================
6432 // function : OnSketchDelete()
6433 // purpose  : 
6434 //=======================================================================
6435 void GeometryGUI::OnSketchDelete()
6436 {
6437   if (GeomGUI->mySketcher.GetmyEdgesNumber() == 1 ) {
6438     QMenuBar* Mb = GeomGUI->myDesktop->getMainMenuBar();
6439     QMenuData* pp;
6440     QMenuItem* item = Mb->findItem(313,&pp);
6441     pp->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
6442     GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6443   }
6444
6445   if (this->mySketcher.Delete())
6446     GeomGUI->ResetState();
6447 }
6448
6449
6450 //=======================================================================
6451 // function : OnSketchClose()
6452 // purpose  : 
6453 //=======================================================================
6454 void GeometryGUI::OnSketchClose()
6455 {
6456   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6457   Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
6458
6459   TopoDS_Wire W = this->mySketcher.Close();
6460   if ( !W.IsNull() ) {
6461     //
6462     GEOM::GEOM_Gen::ListOfIOR_var listShapes = new GEOM::GEOM_Gen::ListOfIOR;
6463     listShapes->length(0);
6464     unsigned int i = 0;
6465
6466     BRepTools_WireExplorer Ex(W);
6467     while ( Ex.More() ) {
6468       TopoDS_Edge E = Ex.Current();
6469       gp_Pnt pt1 , pt2 ;
6470
6471       pt1 = BRep_Tool::Pnt(TopExp::FirstVertex(E));
6472       pt2 = BRep_Tool::Pnt(TopExp::LastVertex(E));
6473
6474       gp_Pnt CenterPoint;
6475       Handle(Geom_Curve) Curve;
6476       Handle(Geom_Circle) Circle;
6477       gp_Circ Circ;
6478       Standard_Real First,Last;
6479
6480       Curve = BRep_Tool::Curve(E,First,Last);
6481       if(Curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
6482         Circle = Handle(Geom_Circle)::DownCast(Curve); // pointer on geom_circ
6483         Circ   = Circle->Circ();                       // gp_Circ
6484         
6485         Curve->D0( (First + Last) / 2. , CenterPoint );
6486
6487         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6488         GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z() );
6489         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6490
6491         GEOM::GEOM_Shape_var arc;
6492
6493         try {
6494           arc = myComponentGeom->MakeArc(pI, pC, pE) ;
6495         }
6496         catch (const SALOME::SALOME_Exception& S_ex) {
6497           QtCatchCorbaException(S_ex);
6498         }
6499
6500         listShapes->length(i+1);
6501         listShapes[i] = strdup(arc->Name());
6502         i++;   
6503      } else {
6504         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6505         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6506         GEOM::GEOM_Shape_var segment;
6507
6508         try {
6509           segment = myComponentGeom->MakeEdge(pI,pE) ;
6510         }       
6511         catch (const SALOME::SALOME_Exception& S_ex) {
6512           QtCatchCorbaException(S_ex);
6513         }
6514
6515         listShapes->length(i+1);
6516         listShapes[i] = strdup(segment->Name());
6517         i++;
6518       }
6519       Ex.Next();
6520     }
6521     GEOM::GEOM_Shape_var Wire = myComponentGeom->MakeWire(listShapes) ;
6522     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, Wire);
6523     Standard_CString type;
6524     GetShapeTypeString(S,type);
6525     Wire->NameType( type );
6526
6527     if ( Display(Wire, "" )) {
6528       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6529     } 
6530   }
6531   GeomGUI->ResetState();
6532   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6533   QMenuData* pp;
6534   QMenuItem* item = Mb->findItem(313,&pp);
6535   pp->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
6536   GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6537 }
6538
6539
6540
6541 //=======================================================================
6542 // function : OnSketchEnd()
6543 // purpose  : 
6544 //=======================================================================
6545 void GeometryGUI::OnSketchEnd()
6546 {
6547   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)this->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6548   Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
6549
6550   TopoDS_Wire W = this->mySketcher.End();
6551   if (!W.IsNull()) {
6552     //
6553     GEOM::GEOM_Gen::ListOfIOR_var listShapes = new GEOM::GEOM_Gen::ListOfIOR;
6554     listShapes->length(0);
6555     unsigned int i = 0;
6556
6557     BRepTools_WireExplorer Ex(W);
6558     while ( Ex.More() ) {
6559       TopoDS_Edge E = TopoDS::Edge( Ex.Current() );
6560       
6561       gp_Pnt pt1 , pt2 ;
6562       pt1 = BRep_Tool::Pnt(TopExp::FirstVertex(E));
6563       pt2 = BRep_Tool::Pnt(TopExp::LastVertex(E));
6564
6565       gp_Pnt CenterPoint;
6566       Handle(Geom_Curve) Curve;
6567       Handle(Geom_Circle) Circle;
6568       gp_Circ Circ;
6569       Standard_Real First,Last;
6570       
6571       Curve = BRep_Tool::Curve(E,First,Last);
6572       if(Curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
6573         Circle = Handle(Geom_Circle)::DownCast(Curve); // pointer on geom_circ
6574         Circ   = Circle->Circ();                       // gp_Circ
6575         
6576         Curve->D0( (First + Last) / 2. , CenterPoint );
6577
6578         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6579         GEOM::PointStruct pC = myComponentGeom->MakePointStruct( CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z() );
6580         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6581
6582         GEOM::GEOM_Shape_var arc;
6583
6584         try {
6585           arc = myComponentGeom->MakeArc(pI, pC, pE) ;
6586         }
6587         catch (const SALOME::SALOME_Exception& S_ex) {
6588           QtCatchCorbaException(S_ex);
6589         }
6590                 
6591         listShapes->length(i+1);
6592         listShapes[i] = strdup(arc->Name());
6593         i++;   
6594       } else {
6595         GEOM::PointStruct pI = myComponentGeom->MakePointStruct( pt1.X(), pt1.Y(), pt1.Z() );
6596         GEOM::PointStruct pE = myComponentGeom->MakePointStruct( pt2.X(), pt2.Y(), pt2.Z() );
6597         GEOM::GEOM_Shape_var segment;
6598         
6599         try {
6600           segment = myComponentGeom->MakeEdge(pI,pE) ;
6601         }
6602         catch (const SALOME::SALOME_Exception& S_ex) {
6603           QtCatchCorbaException(S_ex);
6604         }
6605         
6606         listShapes->length(i+1);
6607         listShapes[i] = strdup(segment->Name());
6608         i++;
6609       }
6610       Ex.Next();
6611     }
6612
6613     GEOM::GEOM_Shape_var Wire = myComponentGeom->MakeWire(listShapes) ;
6614     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, Wire);
6615     Standard_CString type;
6616     GetShapeTypeString(S,type);
6617     Wire->NameType( type );
6618
6619     if ( Display(Wire, "") ) {
6620       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6621     }
6622   }
6623   GeomGUI->ResetState();
6624   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6625   QMenuData* pp;
6626   QMenuItem* item = Mb->findItem(313,&pp);
6627   pp->setItemEnabled( 313, false);  // SKETCH CONTRAINTS
6628   GeomGUI->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6629 }
6630
6631 //=======================================================================
6632 // function : OnSettingsNoconstraint()
6633 // purpose  : 
6634 //=======================================================================
6635 void GeometryGUI::OnSettingsNoconstraint() 
6636 {
6637     this->mySketcher.SetTransitionStatus(NOCONSTRAINT);
6638 }
6639
6640 //=======================================================================
6641 // function : OnSettingsPerpendicular()
6642 // purpose  : 
6643 //=======================================================================
6644 void GeometryGUI::OnSettingsPerpendicular() 
6645 {
6646     this->mySketcher.SetTransitionStatus(PERPENDICULAR);
6647 }
6648
6649 //=======================================================================
6650 // function : OnSettingsTangent()
6651 // purpose  : 
6652 //=======================================================================
6653 void GeometryGUI::OnSettingsTangent() 
6654 {
6655   this->mySketcher.SetTransitionStatus(TANGENT);
6656 }
6657
6658 //=======================================================================
6659 // function : OnSketchOptionsOnoffangledimension()
6660 // purpose  : 
6661 //=======================================================================
6662 void GeometryGUI::OnSketchOptionsOnoffangledimension()
6663 {
6664   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6665   QMenuData* pp;
6666   QMenuItem* item = Mb->findItem(10011,&pp);
6667   pp->setItemChecked(10011,!pp->isItemChecked(10011));
6668   this->mySketcher.SetParameterVisibility(ANGLE_PARAMETER,pp->isItemChecked(10011));
6669 }
6670
6671 //=======================================================================
6672 // function : OnSketchOptionsOnofflengthdimension()
6673 // purpose  : 
6674 //=======================================================================
6675 void GeometryGUI::OnSketchOptionsOnofflengthdimension()
6676 {
6677   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6678   QMenuData* pp;
6679   QMenuItem* item = Mb->findItem(10010,&pp);
6680   pp->setItemChecked(10010,!pp->isItemChecked(10010));
6681   this->mySketcher.SetParameterVisibility(LENGTH_PARAMETER,pp->isItemChecked(10010));
6682 }
6683
6684 //=======================================================================
6685 // function : OnSketchOptionsOnoffradiusdimension()
6686 // purpose  : 
6687 //=======================================================================
6688 void GeometryGUI::OnSketchOptionsOnoffradiusdimension()
6689 {
6690   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6691   QMenuData* pp;
6692   QMenuItem* item = Mb->findItem(10012,&pp);
6693   pp->setItemChecked(10012,!pp->isItemChecked(10012));
6694   this->mySketcher.SetParameterVisibility(RADIUS_PARAMETER,pp->isItemChecked(10012));
6695 }
6696
6697
6698 //=======================================================================
6699 // function : OnSketchOptionsOnoffxdimension()
6700 // purpose  : 
6701 //=======================================================================
6702 void GeometryGUI::OnSketchOptionsOnoffxdimension()
6703 {
6704   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6705   QMenuData* pp;
6706   QMenuItem* item = Mb->findItem(10013,&pp);
6707   pp->setItemChecked(10013,!pp->isItemChecked(10013));
6708   this->mySketcher.SetParameterVisibility(XVALUE_PARAMETER,pp->isItemChecked(10013));
6709 }
6710
6711 //=======================================================================
6712 // function : OnSketchOptionsOnoffydimension()
6713 // purpose  : 
6714 //=======================================================================
6715 void GeometryGUI::OnSketchOptionsOnoffydimension()
6716 {
6717   QMenuBar* Mb = this->myDesktop->getMainMenuBar();
6718   QMenuData* pp;
6719   QMenuItem* item = Mb->findItem(10014,&pp);
6720   pp->setItemChecked(10014,!pp->isItemChecked(10014));
6721   this->mySketcher.SetParameterVisibility(YVALUE_PARAMETER,pp->isItemChecked(10014));
6722 }
6723
6724
6725 //=======================================================================
6726 // function : Archimede()
6727 // purpose  : 
6728 //=======================================================================
6729 void GeometryGUI::Archimede( const Handle(SALOME_InteractiveObject)& IO, 
6730                              const double aWeight,
6731                              const double aWaterDensity,
6732                              const double aMeshingDeflection )
6733 {
6734   try {
6735     if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
6736       Handle(GEOM_InteractiveObject) GIO =
6737         Handle(GEOM_InteractiveObject)::DownCast( IO );
6738       GEOM::GEOM_Shape_var Shape = GeomGUI->myComponentGeom->GetIORFromString( GIO->getIOR() );
6739       
6740       GEOM::GEOM_Shape_var Result = GeomGUI->myComponentGeom->Archimede( Shape, aWeight, aWaterDensity, aMeshingDeflection);
6741       Result->NameType(tr("GEOM_PLANE"));
6742       if ( Display(Result, "") ) {
6743         QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6744       }
6745       return;
6746     }
6747     if ( IO->hasEntry() ) {
6748       SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
6749       SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
6750       SALOMEDS::GenericAttribute_var anAttr;
6751       SALOMEDS::AttributeIOR_var     anIOR;
6752       if ( !obj->_is_nil() ) {
6753         if (obj->FindAttribute(anAttr, "AttributeIOR")) {
6754           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6755           GEOM::GEOM_Shape_var Shape = GeomGUI->myComponentGeom->GetIORFromString( anIOR->Value() );
6756           GEOM::GEOM_Shape_var Result = GeomGUI->myComponentGeom->Archimede( Shape, aWeight, aWaterDensity, aMeshingDeflection);
6757           Result->NameType(tr("GEOM_PLANE"));
6758           if ( Display(Result, "") ) {
6759             QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
6760           }
6761         }
6762       }
6763     }
6764
6765   }
6766   catch (const SALOME::SALOME_Exception& S_ex) {
6767     QtCatchCorbaException(S_ex);
6768   }
6769 }
6770
6771
6772 //=====================================================================================
6773 // EXPORTED METHODS
6774 //=====================================================================================
6775 extern "C"
6776 {
6777   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
6778   {
6779     return GeometryGUI::OnGUIEvent(theCommandID, parent);
6780   }
6781
6782   bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
6783   {
6784     return GeometryGUI::OnKeyPress (pe, parent, studyFrame);
6785   }
6786
6787   bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
6788   {
6789     return GeometryGUI::OnMousePress (pe, parent, studyFrame);
6790   }
6791
6792   bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
6793   {
6794     return GeometryGUI::OnMouseMove (pe, parent, studyFrame);
6795   }
6796
6797   bool SetSettings ( QAD_Desktop* parent )
6798   {
6799     return GeometryGUI::SetSettings( parent );
6800   }
6801
6802   bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
6803                      const QString & theParent, const QString & theObject )
6804   {
6805      return GeometryGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
6806   }
6807
6808   void definePopup ( QString & theContext, QString & theParent, QString & theObject )
6809   {
6810     GeometryGUI::DefinePopup( theContext, theParent, theObject );
6811   }
6812   
6813   bool activeStudyChanged ( QAD_Desktop* parent )
6814   {
6815     GeometryGUI::activeStudyChanged( parent );
6816   }
6817
6818   void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
6819   {
6820     GeometryGUI::BuildPresentation(theIO);
6821   }
6822
6823   void supportedViewType(int* buffer, int bufferSize)
6824   {
6825     if (!buffer || !bufferSize) return;
6826     buffer[0] = (int)VIEW_OCC;
6827     if (--bufferSize) buffer[1] = (int)VIEW_VTK;
6828   }
6829 }
6830
6831 //=====================================================================================
6832 // function : OnFilletGetAll()
6833 // purpose  :
6834 //=====================================================================================
6835 bool GeometryGUI::OnFilletGetAll(const TopoDS_Shape& ShapeTopo, const double Radius, const int SubShapeType, const char* ShapeTopoIOR)
6836 {
6837   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
6838   ListOfID->length(0);
6839
6840   SALOMEDS::Study_var   aStudy = myActiveStudy->getStudyDocument();
6841   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR );
6842   if ( theObj->_is_nil() ) {
6843     myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
6844     return false ;
6845   }
6846   
6847   try {
6848     if( Radius <= Precision::Confusion() )
6849       return false;
6850
6851     GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
6852     GEOM::GEOM_Shape_var result = myComponentGeom->MakeFillet(aShape, Radius, SubShapeType, ListOfID) ;
6853     if ( result->_is_nil() ) {
6854       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
6855       return  false;
6856     }
6857     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
6858     Standard_CString type;
6859     GetShapeTypeString(S,type);
6860     result->NameType( type );
6861
6862     if ( Display( result, "" ))
6863       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
6864   }
6865   catch (const SALOME::SALOME_Exception& S_ex) {
6866     QtCatchCorbaException(S_ex);
6867   }
6868   return true;
6869 }
6870
6871 //=====================================================================================
6872 // function : OnFilletGetSelected()
6873 // purpose  :
6874 //=====================================================================================
6875 bool GeometryGUI::OnFilletGetSelected(const TopoDS_Shape& ShapeTopo,
6876                                       const char* ShapeTopoIOR,
6877                                       const double Radius,
6878                                       const int SubShapeType,
6879                                       Standard_Integer& aLocalContextId,
6880                                       bool& myUseLocalContext )
6881 {
6882   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
6883     return false;
6884   }
6885
6886   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
6887   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
6888   
6889   if( myUseLocalContext == false ) {
6890     /*  No local context opened for fillet method */
6891     myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
6892     return false ;
6893   }
6894   
6895   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
6896   ic->InitSelected();
6897   int nbSelected = ic->NbSelected();
6898   int i = 0;
6899   ic->InitSelected();
6900
6901   while(ic->MoreSelected()) {
6902     TopoDS_Shape s = ic->SelectedShape();
6903     if ( s.ShapeType() == TopAbs_FACE ) {
6904       TopExp_Explorer Exp( s, TopAbs_EDGE );
6905       TopTools_MapOfShape M ;
6906       while ( Exp.More() ) {
6907         if( M.Add(Exp.Current() )) { /* if a new edge : do not add doublons indices */
6908           ListOfID->length( i + 1 );
6909           ListOfID[i] = GetIndex( Exp.Current(), ShapeTopo, (int)TopAbs_EDGE ) ;
6910           i++ ;
6911         }
6912         Exp.Next(); 
6913       }  
6914     }
6915     else {
6916       ListOfID->length( i + 1 );
6917       ListOfID[i] = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType );
6918       i++;
6919     }
6920     ic->NextSelected();
6921   }
6922
6923   GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
6924   GEOM::GEOM_Shape_var aResult ;
6925   try {
6926     aResult = myComponentGeom->MakeFillet( aShape, Radius, 6, ListOfID );
6927
6928     /* local context from DialogBox */
6929     ic->CloseLocalContext(aLocalContextId) ;
6930     myUseLocalContext = false ;
6931
6932     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult);
6933     Standard_CString type;
6934     GetShapeTypeString(S,type);
6935     aResult->NameType( type );
6936
6937     if ( Display( aResult, "") )
6938       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
6939   }
6940   catch (const SALOME::SALOME_Exception& S_ex) {
6941     QtCatchCorbaException(S_ex);
6942   }
6943
6944   if ( myUseLocalContext ) {
6945     /* local context from DialogBox */
6946     ic->CloseLocalContext(aLocalContextId) ;
6947     myUseLocalContext = false ;
6948   }
6949
6950   this->OnDisplayAll(true);
6951   myActiveStudy->updateObjBrowser();
6952   myDesktop->putInfo (tr("GEOM_PRP_READY"));
6953
6954   return true ;  
6955 }
6956
6957 //=====================================================================================
6958 // function : OnChamferGetAll()
6959 // purpose  :
6960 //=====================================================================================
6961 bool GeometryGUI::OnChamferGetAll(const TopoDS_Shape& ShapeTopo, const double D1, const double D2, const int SubShapeType, const char* ShapeTopoIOR)
6962 {
6963  GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
6964   ListOfID->length(0);
6965
6966   SALOMEDS::Study_var   aStudy = myActiveStudy->getStudyDocument();
6967   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR( ShapeTopoIOR );
6968   if ( theObj->_is_nil() ) {
6969     myDesktop->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
6970     return false ;
6971   }
6972   
6973   try {
6974     if( D1 <= Precision::Confusion() )
6975       return false;
6976     if( D2 <= Precision::Confusion() )
6977       return false;
6978
6979     GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
6980     GEOM::GEOM_Shape_var result = myComponentGeom->MakeChamfer(aShape, D1, D2, SubShapeType, ListOfID) ;
6981     if ( result->_is_nil() ) {
6982       myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
6983       return  false;
6984     }
6985
6986     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, result);
6987     Standard_CString type;
6988     GetShapeTypeString(S,type);
6989     result->NameType( type );
6990
6991     if ( Display( result, "") )
6992       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
6993   }
6994   catch (const SALOME::SALOME_Exception& S_ex) {
6995     QtCatchCorbaException(S_ex);
6996   }
6997   return true;
6998 }
6999
7000 //=====================================================================================
7001 // function : OnChamferGetSelected()
7002 // purpose  :
7003 //=====================================================================================
7004 bool GeometryGUI::OnChamferGetSelected(const TopoDS_Shape& ShapeTopo,
7005                                        const char* ShapeTopoIOR,
7006                                        const double D1, const double D2, const int SubShapeType,
7007                                        Standard_Integer& aLocalContextId,
7008                                        bool& myUseLocalContext)
7009 {
7010   if ( this->myActiveStudy->getActiveStudyFrame()->getTypeView() > VIEW_OCC ) {
7011     return false;
7012   }
7013   
7014   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
7015   Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
7016   
7017   if( myUseLocalContext == false ) {
7018     /* No local context opened for chamfer method */
7019     myDesktop->putInfo(tr("GEOM_PRP_ABORT"));
7020     return false ;
7021   }
7022   
7023   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
7024   ic->InitSelected();
7025   int nbSelected = ic->NbSelected();
7026   int i = 0;
7027   ic->InitSelected();
7028
7029   while(ic->MoreSelected()) {
7030     TopoDS_Shape s = ic->SelectedShape();
7031     if ( s.ShapeType() == TopAbs_FACE ) {
7032       TopExp_Explorer Exp( s, TopAbs_EDGE );
7033       TopTools_MapOfShape M ;
7034       while ( Exp.More() ) {
7035         if( M.Add(Exp.Current() )) { /* if a new edge : do not add doublons indices */
7036           ListOfID->length( i + 1 );
7037           ListOfID[i] = GetIndex( Exp.Current(), ShapeTopo, (int)TopAbs_EDGE ) ;
7038           i++ ;
7039         }
7040         Exp.Next(); 
7041       }  
7042     }
7043     else {
7044       ListOfID->length( i + 1 );
7045       ListOfID[i] = GetIndex( ic->SelectedShape(), ShapeTopo, SubShapeType ) ;
7046       i++;
7047     }
7048     ic->NextSelected();
7049   }
7050   
7051   GEOM::GEOM_Shape_var aShape  = myComponentGeom->GetIORFromString( ShapeTopoIOR );
7052   GEOM::GEOM_Shape_var aResult ;
7053   try {
7054     aResult = myComponentGeom->MakeChamfer( aShape, D1, D2, 6, ListOfID );
7055
7056     /* local context from DialogBox */
7057     ic->CloseLocalContext(aLocalContextId) ;
7058     myUseLocalContext = false ;
7059
7060     TopoDS_Shape S = ShapeReader.GetShape(myComponentGeom, aResult);
7061     Standard_CString type;
7062     GetShapeTypeString(S,type);
7063     aResult->NameType( type );
7064
7065     if ( Display( aResult, "") )
7066       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
7067   }
7068   catch (const SALOME::SALOME_Exception& S_ex) {
7069     QtCatchCorbaException(S_ex);
7070   }
7071
7072   if ( myUseLocalContext ) {
7073     /* local context from DialogBox */
7074     ic->CloseLocalContext(aLocalContextId) ;
7075     myUseLocalContext = false ;
7076   }
7077
7078   this->OnDisplayAll(true);
7079   myActiveStudy->updateObjBrowser();
7080   myDesktop->putInfo (tr("GEOM_PRP_READY"));
7081
7082   return true ;  
7083 }
7084
7085 //=====================================================================================
7086 // function : MakeCDGAndDisplay()
7087 // purpose  :
7088 //=====================================================================================
7089 void GeometryGUI::MakeCDGAndDisplay(GEOM::GEOM_Shape_ptr Shape)
7090 {
7091   try {
7092     GEOM::GEOM_Shape_var result = myComponentGeom->MakeCDG( Shape );
7093     if ( result->_is_nil() ) {
7094       myDesktop->putInfo(tr("GEOM_PRP_ABORT") );
7095       return ;
7096     }
7097     result->NameType( tr("GEOM_POINT") );
7098     if ( Display( result ) )
7099       myDesktop->putInfo(tr("GEOM_PRP_DONE"));
7100   }  
7101   catch (const SALOME::SALOME_Exception& S_ex) {
7102     QtCatchCorbaException(S_ex);
7103   }
7104   return  ;
7105 }
7106
7107 bool GeometryGUI::SObjectExist(SALOMEDS::SObject_ptr theFatherObject, const char* IOR) {
7108   SALOMEDS::Study_var aStudy = GeomGUI->myActiveStudy->getStudyDocument();
7109   SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theFatherObject);
7110   SALOMEDS::SObject_var RefSO;
7111   SALOMEDS::GenericAttribute_var anAttr;
7112   SALOMEDS::AttributeIOR_var     anIOR;
7113   for (; it->More();it->Next()) {
7114     SALOMEDS::SObject_var SO= it->Value();
7115     if (SO->FindAttribute(anAttr, "AttributeIOR") ) {
7116       anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
7117       if ( strcmp( anIOR->Value(), IOR ) == 0 )
7118         return true;
7119     }
7120     if ( SO->ReferencedObject( RefSO ) ) {
7121       if (RefSO->FindAttribute(anAttr, "AttributeIOR") ) {
7122         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
7123         if ( strcmp( anIOR->Value(), IOR ) == 0 )
7124           return true;
7125       }
7126     }
7127   }
7128   return false;
7129 }