Salome HOME
ENV: Windows porting
[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 "VTKViewer_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       VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
403       
404       int themode = myRenderInter->GetDisplayMode();
405       vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
406       vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
407       
408       Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(aResult->Name(), myGeomGUI->GetFatherior(), "GEOM");
409       
410       if(SO->_is_nil()) {
411         SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(theObj);
412         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
413         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
414         anIOR->SetValue(aResult->Name());
415         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
416         aName = SALOMEDS::AttributeName::_narrow(anAttr);
417         aName->SetValue(nameG);
418         
419         anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
420         aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
421         if(S.ShapeType() == TopAbs_COMPOUND)
422           aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
423         else if(S.ShapeType() == TopAbs_COMPSOLID)
424           aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
425         else if(S.ShapeType() == TopAbs_SOLID)
426           aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
427         else if(S.ShapeType() == TopAbs_SHELL)
428           aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
429         else if(S.ShapeType() == TopAbs_FACE)
430           aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
431         else if(S.ShapeType() == TopAbs_WIRE)
432           aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
433         else if(S.ShapeType() == TopAbs_EDGE)
434           aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
435         else if(S.ShapeType() == TopAbs_VERTEX)
436           aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
437
438         SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
439         aStudyBuilder->Addreference(newObj1, newObj);
440         IO->setEntry(newObj->GetID());
441       }
442       else {
443         allreadyexist = true;
444         if(!this->SObjectExist(theObj, aResult->Name())) {
445           SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
446           aStudyBuilder->Addreference(newObj1, SO);
447           IO->setEntry(SO->GetID());
448         }
449       }
450       
451       if(!allreadyexist) {
452         vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(S,0,themode,Standard_True);
453         theActors->InitTraversal();
454         vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
455         while(!(anActor==NULL)) {
456           GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
457           GActor->setIO(IO);
458           GActor->setName(nameG);
459           theRenderer->AddActor(GActor);
460           renWin->Render();
461           anActor = (vtkActor*)theActors->GetNextActor();
462         }
463       }
464     }
465   }
466
467   // commit transaction
468   op->finish();
469
470   QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
471   QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_READY"));
472   */
473   return true;
474 }
475
476
477 //=====================================================================================
478 // function : OnSubShapeGetSelected()
479 // purpose  :
480 //=====================================================================================
481 bool EntityGUI::OnSubShapeGetSelected(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR, const int SubShapeType, Standard_Integer& aLocalContextId, bool& myUseLocalContext)
482 {
483   SUIT_Session::session()->activeApplication()->putInfo("OnSubShapeGetSelected method from EntityGUI should be reimplemented ...");
484  //  //* Test the type of viewer */
485 //   if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
486 //     return false;
487
488 //   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
489 //   SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
490 //   if(theObj->_is_nil()) {
491 //     QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
492 //     return false;
493 //   }
494
495 //   OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
496 //   Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
497   
498 //   if( myUseLocalContext == false ) {
499 //     /* local context is from DialogBox */
500 //     MESSAGE("Error : No local context opened for sub shapes method" << endl ) ;
501 //     return false ;
502 //   }
503
504 //   GEOM::GEOM_Shape_var aShape  = myGeom->GetIORFromString( ShapeTopoIOR );
505 //   TopoDS_Shape mainTopo = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
506
507 //   TopoDS_Shape mainShape;
508 //   bool main = false;
509 //   while(!main) {
510 //     if(aShape->IsMainShape()) {
511 //       mainShape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
512 //       main = true;
513 //     }
514 //     else
515 //       aShape = myGeom->GetIORFromString(aShape->MainName());
516 //   }
517
518 //   GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
519 //   ic->InitSelected();
520 //   int nbSelected = ic->NbSelected();
521 //   ListOfID->length(nbSelected);
522   
523 //   TopoDS_Compound compound;
524 //   ic->InitSelected(); /* to init again */ 
525 //   BRep_Builder B;
526 //   B.MakeCompound(compound);
527
528 //   int i = 0;
529 //   /* We create a unique compound containing all the sub shapes selected by user as attribute of the main shape */
530 //   /* the compound is homogenous by selection */
531 //   while(ic->MoreSelected()) {
532 //     int index = myGeomBase->GetIndex(ic->SelectedShape(), mainShape, SubShapeType);
533 //     ListOfID[i] = index;
534 //     B.Add(compound, ic->SelectedShape());
535 //     i++;
536 //     ic->NextSelected();
537 //   }
538  
539 //   /* Test if user has selected sub shapes */
540 //   if(ListOfID->length() < 1)
541 //     return false;
542
543 //   GEOM::GEOM_Shape_var aResult;
544 //   try {
545 //     aResult = myGeom->SubShape(aShape, SubShapeType, ListOfID);
546 //   }
547 //   catch (const SALOME::SALOME_Exception& S_ex) {
548 //     SalomeApp_Tools::QtCatchCorbaException(S_ex);
549 //   }
550
551 //   /* local context from DialogBox */
552 //   ic->CloseLocalContext(aLocalContextId);
553 //   myUseLocalContext = false ;
554
555 //   char* nameG = (char *)malloc(20);
556 //   Standard_CString Type;
557
558 //   Handle(GEOM_AISShape) result; 
559 //   Handle(GEOM_InteractiveObject) IO;
560
561 //   if(nbSelected == 1) {
562 //     TopExp_Explorer Exp (compound, TopAbs_ShapeEnum(SubShapeType));
563 //     if(Exp.More()) {
564 //       if(myGeomBase->GetShapeTypeString(Exp.Current(),Type)) {
565 //      aResult->NameType(Type);
566 //      sprintf (nameG, "%s_%d", Type, myGeomBase->GetIndex( Exp.Current(), mainTopo, SubShapeType));
567 //       } 
568 //       else {
569 //      aResult->NameType(tr("GEOM_SHAPE"));
570 //      sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->myNbGeom++);
571 //       }
572 //       result = new GEOM_AISShape(Exp.Current(), nameG);
573 //       IO = new GEOM_InteractiveObject(aResult->Name(), myGeomGUI->GetFatherior(), "GEOM");
574 //     }
575 //   }
576 //   else {
577 //     if ( myGeomBase->GetShapeTypeString(compound,Type)) {
578 //       aResult->NameType(Type);
579 //       sprintf (nameG, "%s_%d", Type, myGeomGUI->myNbGeom++);
580 //     } else {
581 //       aResult->NameType(tr("GEOM_SHAPE"));
582 //       sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->myNbGeom++);
583 //     }
584 //     result = new GEOM_AISShape(compound, nameG);
585 //     IO = new GEOM_InteractiveObject(aResult->Name(), myGeomGUI->GetFatherior(), "GEOM");
586 //   }
587   
588 //   SALOMEDS::SObject_var SO = aStudy->FindObjectIOR(aResult->Name());
589   
590 //   /* open transaction */
591 //   QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
592 //   op->start();
593   
594 //   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
595 //   SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
596 //   SALOMEDS::GenericAttribute_var anAttr;
597 //   SALOMEDS::AttributeName_var aName;
598 //   SALOMEDS::AttributeIOR_var anIOR;
599 //   SALOMEDS::AttributePixMap_var aPixmap;
600  
601 //   bool allreadyexist = false;
602
603 //   if(SO->_is_nil()) {
604 //     SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(theObj);
605 //     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
606 //     anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
607 //     anIOR->SetValue(aResult->Name());
608 //     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
609 //     aName = SALOMEDS::AttributeName::_narrow(anAttr);
610 //     aName->SetValue(result->getName());
611     
612 //     anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
613 //     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
614 //     if(result->Shape().ShapeType() == TopAbs_COMPOUND)
615 //       aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
616 //     else if(result->Shape().ShapeType() == TopAbs_COMPSOLID)
617 //       aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
618 //     else if(result->Shape().ShapeType() == TopAbs_SOLID)
619 //       aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
620 //     else if(result->Shape().ShapeType() == TopAbs_SHELL)
621 //       aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
622 //     else if(result->Shape().ShapeType() == TopAbs_FACE)
623 //       aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
624 //     else if(result->Shape().ShapeType() == TopAbs_WIRE)
625 //       aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
626 //     else if(result->Shape().ShapeType() == TopAbs_EDGE)
627 //       aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
628 //     else if(result->Shape().ShapeType() == TopAbs_VERTEX)
629 //       aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
630
631 //     SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
632 //     aStudyBuilder->Addreference(newObj1, newObj);
633     
634 //     IO->setEntry(newObj->GetID());
635 //     aResult->StudyShapeId(newObj->GetID());
636 //   } 
637 //   else {
638 //     allreadyexist = true;
639 //     if(!this->SObjectExist(theObj, aResult->Name())) {
640 //       SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(theObj);
641 //       aStudyBuilder->Addreference(newObj1, SO);
642     
643 //       IO->setEntry(SO->GetID());
644 //       aResult->StudyShapeId(SO->GetID());
645 //     }
646 //   }
647   
648 //   /* commit transaction */
649 //   op->finish();
650   
651 //   result->setIO(IO);
652 //   result->setName(nameG);
653
654 //   if(!allreadyexist)
655 //     ic->Display(result);
656
657 //   DisplayGUI* myDisplayGUI = new DisplayGUI();
658 //   myDisplayGUI->OnDisplayAll(true);
659
660 //   QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
661 //   QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_READY"));
662   return true;
663 }
664
665
666 //=====================================================================================
667 // EXPORTED METHODS
668 //=====================================================================================
669 extern "C"
670 {
671 #ifdef WNT
672         __declspec( dllexport )
673 #endif
674   GEOMGUI* GetLibGUI( GeometryGUI* parent )
675   {
676     return EntityGUI::GetEntityGUI( parent );
677   }
678 }