]> SALOME platform Git repositories - modules/geom.git/blob - src/EntityGUI/EntityGUI.cxx
Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / EntityGUI / EntityGUI.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   : EntityGUI.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header: 
28
29 #include "EntityGUI.h"
30
31 #include "QAD_RightFrame.h"
32 #include "OCCViewer_Viewer3d.h"
33 #include "VTKViewer_ViewFrame.h"
34 #include "GEOM_AssemblyBuilder.h"
35 #include "SALOMEGUI_ImportOperation.h"
36 #include "SALOMEGUI_QtCatchCorbaException.hxx"
37
38 #include <TopoDS_Compound.hxx>
39 #include <BRep_Builder.hxx>
40 #include <TopExp_Explorer.hxx>
41
42 #include "DisplayGUI.h"
43
44 #include "EntityGUI_SketcherDlg.h" // Sketcher
45 #include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE
46
47 #include "utilities.h"
48
49 using namespace std;
50
51 //=======================================================================
52 // function : EntityGUI()
53 // purpose  : Constructor
54 //=======================================================================
55 EntityGUI::EntityGUI() :
56   QObject()
57 {
58   myGeomBase = new GEOMBase();
59   myGeomGUI = GEOMContext::GetGeomGUI();
60   myGeom = myGeomGUI->myComponentGeom;
61
62   mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
63   mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
64 }
65
66
67 //=======================================================================
68 // function : ~EntityGUI()
69 // purpose  : Destructor
70 //=======================================================================
71 EntityGUI::~EntityGUI()
72 {
73 }
74
75
76 //=======================================================================
77 // function : OnGUIEvent()
78 // purpose  : 
79 //=======================================================================
80 bool EntityGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
81 {
82   EntityGUI* myEntityGUI = new EntityGUI();
83   myEntityGUI->myGeomGUI->EmitSignalDeactivateDialog();
84   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
85
86   switch (theCommandID)
87     {
88     case 404: // SKETCHER
89       {
90         ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->onViewTop(); // DCQ : 28/02/2002
91         EntityGUI_SketcherDlg* aDlg = new EntityGUI_SketcherDlg(parent, "", myEntityGUI, Sel);
92         break;
93       }
94     case 407: // EXPLODE : use ic
95       {
96         Handle(AIS_InteractiveContext) ic;
97         if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
98           OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
99           ic = v3d->getAISContext();
100         }
101         EntityGUI_SubShapeDlg *aDlg = new EntityGUI_SubShapeDlg(parent, "", myEntityGUI, Sel, ic);
102         break ;
103       }
104     default:
105       {
106         parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
107         break;
108       }
109     }
110   return true;
111 }
112
113
114 //=======================================================================
115 // function : OnSketchEnd()
116 // purpose  : 
117 //=======================================================================
118 void EntityGUI::OnSketchEnd(const char *Cmd)
119 {
120   try {
121     GEOM::GEOM_Shape_var result = myGeom->MakeSketcher(Cmd);
122     if(result->_is_nil()) {
123       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
124       return;
125     }
126     result->NameType(tr("GEOM_WIRE"));
127     if(myGeomBase->Display(result))
128       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
129   }
130   catch(const SALOME::SALOME_Exception& S_ex) {
131     QtCatchCorbaException(S_ex);
132   }
133   return;
134 }
135
136
137 //=====================================================================================
138 // function : DisplaySimulationShape() 
139 // purpose  : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
140 //=====================================================================================
141 void EntityGUI::DisplaySimulationShape(const TopoDS_Shape& S1, const TopoDS_Shape& S2) 
142 {
143   //NRI DEBUG : 14/02/2002
144   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
145     return;
146         
147   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
148   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
149   try {
150     if(!S1.IsNull()) {
151       /* erase any previous */
152       ic->Erase(mySimulationShape1, Standard_True, Standard_False);
153       ic->ClearPrs(mySimulationShape1);
154       
155       mySimulationShape1 = new AIS_Shape(TopoDS_Shape());
156       mySimulationShape1->Set(S1);
157       mySimulationShape1->SetColor(Quantity_NOC_RED);
158     
159       ic->Deactivate(mySimulationShape1);
160       ic->Display(mySimulationShape1, Standard_False);
161       mySimulationShape1->UnsetColor();
162     }
163     if(!S2.IsNull()) {
164       ic->Erase(mySimulationShape2, Standard_True, Standard_False);
165       ic->ClearPrs(mySimulationShape2);
166
167       mySimulationShape2 = new AIS_Shape(TopoDS_Shape());
168       mySimulationShape2->Set(S2);
169       mySimulationShape2->SetColor(Quantity_NOC_VIOLET);
170
171       ic->Deactivate(mySimulationShape2);
172       ic->Display(mySimulationShape2, Standard_False);
173       mySimulationShape2->UnsetColor();
174     }
175     ic->UpdateCurrentViewer();
176   }
177   catch(Standard_Failure) {
178     MESSAGE("Exception catched in EntityGUI::DisplaySimulationShape ");
179   } 
180   return;
181 }
182
183
184 //==================================================================================
185 // function : EraseSimulationShape()
186 // purpose  : Clears the display of 'mySimulationShape' a pure graphical shape
187 //==================================================================================
188 void EntityGUI::EraseSimulationShape(int Sh)
189 {
190   int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
191   for(int i = 0; i < count; i++) {
192     if(QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
193       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
194       Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
195       if(Sh < 1) {
196         ic->Erase(mySimulationShape1, Standard_True, Standard_False);
197         ic->ClearPrs(mySimulationShape1);
198       }
199       if(Sh <= 1) {
200         ic->Erase(mySimulationShape2, Standard_True, Standard_False);
201         ic->ClearPrs(mySimulationShape2);
202       }
203       ic->UpdateCurrentViewer();
204     } 
205   }
206 }
207
208
209 //=====================================================================================
210 // function : SObjectExist()
211 // purpose  :
212 //=====================================================================================
213 bool EntityGUI::SObjectExist(SALOMEDS::SObject_ptr theFatherObject, const char* IOR)
214 {
215   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
216   SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theFatherObject);
217   SALOMEDS::SObject_var RefSO;
218   SALOMEDS::GenericAttribute_var anAttr;
219   SALOMEDS::AttributeIOR_var anIOR;
220   for(; it->More();it->Next()) {
221     SALOMEDS::SObject_var SO= it->Value();
222     if(SO->FindAttribute(anAttr, "AttributeIOR")) {
223       anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
224       if(strcmp( anIOR->Value(), IOR ) == 0)
225         return true;
226     }
227     if(SO->ReferencedObject(RefSO)) {
228       if(RefSO->FindAttribute(anAttr, "AttributeIOR")) {
229         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
230         if(strcmp(anIOR->Value(), IOR) == 0)
231           return true;
232       }
233     }
234   }
235   return false;
236 }
237
238
239 //=====================================================================================
240 // function : OnSubShapeGetAll()
241 // purpose  : Explode a shape in all sub shapes with a SubShapeType
242 //=====================================================================================
243 bool EntityGUI::OnSubShapeGetAll(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR, const int SubShapeType)
244 {
245   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
246   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
247   if(theObj->_is_nil()) {
248     QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
249     return false;
250   }
251
252   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
253   SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
254   SALOMEDS::GenericAttribute_var anAttr;
255   SALOMEDS::AttributeName_var aName;
256   SALOMEDS::AttributeIOR_var anIOR;
257   SALOMEDS::AttributePixMap_var aPixmap;
258
259   /* We create a sub object for each sub shape as attribute of the main object  */
260   /* Each sub object contains list (length=1) containing its index in the main shape */
261   GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);
262   GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
263   GEOM::GEOM_Shape_var aResult;
264   
265   try {
266     listGeomShapes = myGeom->SubShapeAll(aShape, SubShapeType);
267     if(listGeomShapes->length() < 1) {
268       QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_ABORT"));
269       return false;
270     }
271   }
272   catch(const SALOME::SALOME_Exception& S_ex) {
273     QtCatchCorbaException(S_ex);
274   }
275   
276   /* open transaction */
277   QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
278   op->start();
279   
280   TopoDS_Shape mainTopo = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
281   TopoDS_Shape mainShape;
282   bool main = false;
283   while(!main) {
284     if(aShape->IsMainShape()) {
285       mainShape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
286       main = true;
287     } 
288     else
289       aShape = myGeom->GetIORFromString(aShape->MainName());
290   }
291   
292   /* Loop on each sub shape created */
293   /* int i = 1 ; /* index for the nameType */  
294   for(int j=0; j<listGeomShapes->length(); j++) {
295     /* Get each sub shape extracted CORBA and OCC */
296     aResult = listGeomShapes[j] ;    
297     TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
298     
299     if (S.IsNull()) {
300       QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_ABORT"));
301       return false;
302     }
303     
304     /* Set the nameType of sub shape */
305     char* nameG = (char *)malloc(20);
306     Standard_CString Type;
307     if(myGeomBase->GetShapeTypeString(S, Type)) {
308       aResult->NameType(Type);
309       sprintf(nameG, "%s_%d", Type, myGeomBase->GetIndex(S, mainShape, SubShapeType));
310     } 
311     else {
312       aResult->NameType(tr("GEOM_SHAPE"));
313       sprintf(nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->myNbGeom++);
314     }
315     SALOMEDS::SObject_var SO = aStudy->FindObjectIOR(aResult->Name());
316
317     bool allreadyexist = false;
318           
319     if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
320       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
321       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
322       
323       Handle(GEOM_AISShape) result = new GEOM_AISShape(S, nameG);      
324       Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(aResult->Name(), myGeomGUI->GetFatherior(), "GEOM");
325       
326       MESSAGE ("SO->_is_nil() " << SO->_is_nil())
327
328       if(SO->_is_nil()) {
329         SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(theObj);
330         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
331         aName = SALOMEDS::AttributeName::_narrow(anAttr);
332         aName->SetValue(nameG);
333         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
334         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
335         anIOR->SetValue(aResult->Name());
336
337         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
338         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
339         MESSAGE(" Type " << S.ShapeType())
340         if (S.ShapeType() == TopAbs_COMPOUND)
341           aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
342         else if(S.ShapeType() == TopAbs_COMPSOLID)
343           aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
344         else if(S.ShapeType() == TopAbs_SOLID)
345           aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
346         else if(S.ShapeType() == TopAbs_SHELL)
347           aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
348         else if(S.ShapeType() == TopAbs_FACE)
349           aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
350         else if(S.ShapeType() == TopAbs_WIRE)
351           aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
352         else if(S.ShapeType() == TopAbs_EDGE)
353           aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
354         else if(S.ShapeType() == TopAbs_VERTEX)
355           aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
356
357         MESSAGE(" aPixmap->GetPixMap " << aPixmap->GetPixMap())
358
359         SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
360         aStudyBuilder->Addreference(newObj1, newObj);
361         IO->setEntry(newObj->GetID());
362
363         aResult->StudyShapeId(newObj->GetID());
364       }
365       else {
366         allreadyexist = true;
367         if(!this->SObjectExist(theObj, aResult->Name())) {
368           SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
369           aStudyBuilder->Addreference(newObj1, SO);
370           IO->setEntry(SO->GetID());
371           aResult->StudyShapeId(SO->GetID());
372         }
373       }
374       
375       result->setIO(IO);
376       result->setName(nameG);
377       if(!allreadyexist)
378         ic->Display(result);
379       
380     }
381     else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
382       VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
383       
384       int themode = myRenderInter->GetDisplayMode();
385       vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
386       vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
387       
388       Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(aResult->Name(), myGeomGUI->GetFatherior(), "GEOM");
389       
390       if(SO->_is_nil()) {
391         SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(theObj);
392         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
393         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
394         anIOR->SetValue(aResult->Name());
395         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
396         aName = SALOMEDS::AttributeName::_narrow(anAttr);
397         aName->SetValue(nameG);
398         
399         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
400         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
401         if(S.ShapeType() == TopAbs_COMPOUND)
402           aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
403         else if(S.ShapeType() == TopAbs_COMPSOLID)
404           aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
405         else if(S.ShapeType() == TopAbs_SOLID)
406           aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
407         else if(S.ShapeType() == TopAbs_SHELL)
408           aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
409         else if(S.ShapeType() == TopAbs_FACE)
410           aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
411         else if(S.ShapeType() == TopAbs_WIRE)
412           aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
413         else if(S.ShapeType() == TopAbs_EDGE)
414           aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
415         else if(S.ShapeType() == TopAbs_VERTEX)
416           aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
417
418         SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
419         aStudyBuilder->Addreference(newObj1, newObj);
420         IO->setEntry(newObj->GetID());
421       }
422       else {
423         allreadyexist = true;
424         if(!this->SObjectExist(theObj, aResult->Name())) {
425           SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
426           aStudyBuilder->Addreference(newObj1, SO);
427           IO->setEntry(SO->GetID());
428         }
429       }
430       
431       if(!allreadyexist) {
432         vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(S,0,themode,Standard_True);
433         theActors->InitTraversal();
434         vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
435         while(!(anActor==NULL)) {
436           GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
437           GActor->setIO(IO);
438           GActor->setName(nameG);
439           theRenderer->AddActor(GActor);
440           renWin->Render();
441           anActor = (vtkActor*)theActors->GetNextActor();
442         }
443       }
444     }
445   }
446
447   /* commit transaction */
448   op->finish();
449
450   QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
451   QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_READY"));
452   return true;
453 }
454
455
456 //=====================================================================================
457 // function : OnSubShapeGetSelected()
458 // purpose  :
459 //=====================================================================================
460 bool EntityGUI::OnSubShapeGetSelected(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR, const int SubShapeType, Standard_Integer& aLocalContextId, bool& myUseLocalContext)
461 {
462   //* Test the type of viewer */
463   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
464     return false;
465
466   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
467   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
468   if(theObj->_is_nil()) {
469     QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
470     return false;
471   }
472
473   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
474   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
475   
476   if( myUseLocalContext == false ) {
477     /* local context is from DialogBox */
478     MESSAGE("Error : No local context opened for sub shapes method" << endl ) ;
479     return false ;
480   }
481
482   GEOM::GEOM_Shape_var aShape  = myGeom->GetIORFromString( ShapeTopoIOR );
483   TopoDS_Shape mainTopo = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
484
485   TopoDS_Shape mainShape;
486   bool main = false;
487   while(!main) {
488     if(aShape->IsMainShape()) {
489       mainShape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
490       main = true;
491     }
492     else
493       aShape = myGeom->GetIORFromString(aShape->MainName());
494   }
495
496   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
497   ic->InitSelected();
498   int nbSelected = ic->NbSelected();
499   ListOfID->length(nbSelected);
500   
501   TopoDS_Compound compound;
502   ic->InitSelected(); /* to init again */ 
503   BRep_Builder B;
504   B.MakeCompound(compound);
505
506   int i = 0;
507   /* We create a unique compound containing all the sub shapes selected by user as attribute of the main shape */
508   /* the compound is homogenous by selection */
509   while(ic->MoreSelected()) {
510     int index = myGeomBase->GetIndex(ic->SelectedShape(), mainShape, SubShapeType);
511     ListOfID[i] = index;
512     B.Add(compound, ic->SelectedShape());
513     i++;
514     ic->NextSelected();
515   }
516  
517   /* Test if user has selected sub shapes */
518   if(ListOfID->length() < 1)
519     return false;
520
521   GEOM::GEOM_Shape_var aResult;
522   try {
523     aResult = myGeom->SubShape(aShape, SubShapeType, ListOfID);
524   }
525   catch (const SALOME::SALOME_Exception& S_ex) {
526     QtCatchCorbaException(S_ex);
527   }
528
529   /* local context from DialogBox */
530   ic->CloseLocalContext(aLocalContextId);
531   myUseLocalContext = false ;
532
533   char* nameG = (char *)malloc(20);
534   Standard_CString Type;
535
536   Handle(GEOM_AISShape) result; 
537   Handle(GEOM_InteractiveObject) IO;
538
539   if(nbSelected == 1) {
540     TopExp_Explorer Exp (compound, TopAbs_ShapeEnum(SubShapeType));
541     if(Exp.More()) {
542       if(myGeomBase->GetShapeTypeString(Exp.Current(),Type)) {
543         aResult->NameType(Type);
544         sprintf (nameG, "%s_%d", Type, myGeomBase->GetIndex( Exp.Current(), mainTopo, SubShapeType));
545       } 
546       else {
547         aResult->NameType(tr("GEOM_SHAPE"));
548         sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->myNbGeom++);
549       }
550       result = new GEOM_AISShape(Exp.Current(), nameG);
551       IO = new GEOM_InteractiveObject(aResult->Name(), myGeomGUI->GetFatherior(), "GEOM");
552     }
553   }
554   else {
555     if ( myGeomBase->GetShapeTypeString(compound,Type)) {
556       aResult->NameType(Type);
557       sprintf (nameG, "%s_%d", Type, myGeomGUI->myNbGeom++);
558     } else {
559       aResult->NameType(tr("GEOM_SHAPE"));
560       sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->myNbGeom++);
561     }
562     result = new GEOM_AISShape(compound, nameG);
563     IO = new GEOM_InteractiveObject(aResult->Name(), myGeomGUI->GetFatherior(), "GEOM");
564   }
565   
566   SALOMEDS::SObject_var SO = aStudy->FindObjectIOR(aResult->Name());
567   
568   /* open transaction */
569   QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
570   op->start();
571   
572   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
573   SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
574   SALOMEDS::GenericAttribute_var anAttr;
575   SALOMEDS::AttributeName_var aName;
576   SALOMEDS::AttributeIOR_var anIOR;
577   SALOMEDS::AttributePixMap_var aPixmap;
578  
579   bool allreadyexist = false;
580
581   if(SO->_is_nil()) {
582     SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(theObj);
583     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
584     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
585     anIOR->SetValue(aResult->Name());
586     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
587     aName = SALOMEDS::AttributeName::_narrow(anAttr);
588     aName->SetValue(result->getName());
589     
590     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
591     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
592     if(result->Shape().ShapeType() == TopAbs_COMPOUND)
593       aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
594     else if(result->Shape().ShapeType() == TopAbs_COMPSOLID)
595       aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
596     else if(result->Shape().ShapeType() == TopAbs_SOLID)
597       aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
598     else if(result->Shape().ShapeType() == TopAbs_SHELL)
599       aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
600     else if(result->Shape().ShapeType() == TopAbs_FACE)
601       aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
602     else if(result->Shape().ShapeType() == TopAbs_WIRE)
603       aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
604     else if(result->Shape().ShapeType() == TopAbs_EDGE)
605       aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
606     else if(result->Shape().ShapeType() == TopAbs_VERTEX)
607       aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
608
609     SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
610     aStudyBuilder->Addreference(newObj1, newObj);
611     
612     IO->setEntry(newObj->GetID());
613     aResult->StudyShapeId(newObj->GetID());
614   } 
615   else {
616     allreadyexist = true;
617     if(!this->SObjectExist(theObj, aResult->Name())) {
618       SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
619       aStudyBuilder->Addreference(newObj1, SO);
620     
621       IO->setEntry(SO->GetID());
622       aResult->StudyShapeId(SO->GetID());
623     }
624   }
625   
626   /* commit transaction */
627   op->finish();
628   
629   result->setIO(IO);
630   result->setName(nameG);
631
632   if(!allreadyexist)
633     ic->Display(result);
634
635   DisplayGUI* myDisplayGUI = new DisplayGUI();
636   myDisplayGUI->OnDisplayAll(true);
637
638   QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
639   QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_READY"));
640   return true;
641 }
642
643
644 //=====================================================================================
645 // EXPORTED METHODS
646 //=====================================================================================
647 extern "C"
648 {
649   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
650   {return EntityGUI::OnGUIEvent(theCommandID, parent);}
651 }