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