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