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