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