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