1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DisplayGUI.cxx
25 // Author : Damien COQUERET
30 #include "DisplayGUI.h"
32 #include "QAD_RightFrame.h"
33 #include "GEOM_AssemblyBuilder.h"
34 #include "VTKViewer_ViewFrame.h"
35 #include "OCCViewer_ViewFrame.h"
36 #include "OCCViewer_Viewer3d.h"
37 #include "SALOMEGUI_ImportOperation.h"
38 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include <AIS_ListIteratorOfListOfInteractive.hxx>
42 //=======================================================================
43 // function : DisplayGUI()
44 // purpose : Constructor
45 //=======================================================================
46 DisplayGUI::DisplayGUI() :
49 myGeomBase = new GEOMBase();
50 myGeomGUI = GEOMContext::GetGeomGUI();
51 myGeom = myGeomGUI->myComponentGeom;
55 //=======================================================================
56 // function : ~DisplayGUI()
57 // purpose : Destructor
58 //=======================================================================
59 DisplayGUI::~DisplayGUI()
64 //=======================================================================
65 // function : OnGUIEvent()
67 //=======================================================================
68 bool DisplayGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
70 DisplayGUI* myDisplayGUI = new DisplayGUI();
74 case 211: // MENU VIEW - WIREFRAME/SHADING
76 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
77 QApplication::setOverrideCursor(waitCursor);
79 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
81 int themode = myRenderInter->GetDisplayMode();
83 myRenderInter->SetDisplayMode(1);
84 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_WIREFRAME"));
87 myRenderInter->SetDisplayMode(0);
88 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_SHADING"));
91 QApplication::restoreOverrideCursor();
93 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
94 QApplication::setOverrideCursor(Qt::waitCursor);
96 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
97 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
98 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
99 AIS_DisplayMode newmode = (mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame);
101 AIS_ListOfInteractive List;
102 ic->DisplayedObjects(List);
103 AIS_ListOfInteractive List1;
104 ic->ObjectsInCollector(List1);
107 AIS_ListIteratorOfListOfInteractive ite(List);
109 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
110 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
111 ic->SetDisplayMode(aSh,Standard_Integer(newmode),true);
116 ic->SetDisplayMode(newmode, Standard_False);
118 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_WIREFRAME"));
120 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_SHADING"));
122 QApplication::restoreOverrideCursor();
126 case 212: // MENU VIEW - DISPLAY ALL
128 myDisplayGUI->OnDisplayAll();
131 case 213: // MENU VIEW - DISPLAY ONLY
133 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
134 myDisplayGUI->OnVTKDisplayOnly();
135 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
136 myDisplayGUI->OnDisplayOnly();
139 case 214: // MENU VIEW - ERASE ALL
141 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
142 ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->EraseAll();
143 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
144 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
145 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
147 ic->EraseAll(Standard_True, Standard_False);
148 ic->Display(v3d->getTrihedron());
152 case 215: // MENU VIEW - ERASE ONLY
154 myDisplayGUI->OnErase();
157 case 8031: // POPUP VIEWER - WIREFRAME/SHADING
159 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
161 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
163 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
164 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
166 QApplication::setOverrideCursor(Qt::waitCursor);
167 for(;It.More();It.Next()) {
168 Handle(SALOME_InteractiveObject) IOS = It.Value();
169 myRenderInter->SwitchRepresentation(IOS, false);
171 myRenderInter->Render();
172 QApplication::restoreOverrideCursor();
174 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
175 QApplication::setOverrideCursor(Qt::waitCursor);
176 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
177 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
178 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
179 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
180 for(;It.More();It.Next()) {
181 Handle(SALOME_InteractiveObject) IObject = It.Value();
182 Standard_Boolean found;
183 Handle(GEOM_AISShape) Shape = myDisplayGUI->myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true);
184 if(!Shape.IsNull()) {
185 AIS_DisplayMode mode = (AIS_DisplayMode)Shape->DisplayMode();
187 mode = (AIS_DisplayMode)ic->DisplayMode();
189 ic->SetDisplayMode(Shape, mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame, false);
192 ic->UpdateCurrentViewer();
194 QApplication::restoreOverrideCursor();
199 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
207 //=================================================================================
208 // function : BuildPresentation()
210 //=================================================================================
211 void DisplayGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
213 DisplayGUI* myDisplayGUI = new DisplayGUI();
215 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
216 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
218 OCCViewer_Viewer3d* v3d;
219 Handle(AIS_InteractiveContext) ic;
220 vtkRenderer* Renderer;
222 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
223 v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
224 ic = v3d->getAISContext();
226 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
227 Renderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
233 MESSAGE("BuildPresentation(): null SALOME_InteractiveObject passed")
235 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
238 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
240 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry());
242 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
244 SALOMEDS::GenericAttribute_var anAttr;
245 SALOMEDS::AttributeName_var aName;
246 SALOMEDS::AttributeIOR_var anIOR;
248 if(myRenderInter->isInViewer(theIO)) {
249 myRenderInter->Display(theIO, false);
253 if(!obj->_is_nil()) {
254 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
255 // this SObject may be GEOM module root SObject
257 bool useSubItems = false;
258 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
259 if(myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
260 while (anIter->More() && !useSubItems) {
261 SALOMEDS::SObject_var subobj = anIter->Value();
262 SALOMEDS::GenericAttribute_var aTmpAttr;
263 if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
264 if (!myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
277 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
278 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
279 GEOM::GEOM_Shape_var aShape = myDisplayGUI->myGeom->GetIORFromString(anIOR->Value());
280 TopoDS_Shape Shape = myDisplayGUI->myGeomGUI->GetShapeReader().GetShape(myDisplayGUI->myGeom,aShape);
282 if(obj->FindAttribute(anAttr, "AttributeName")) {
283 aName = SALOMEDS::AttributeName::_narrow(anAttr);
285 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
286 vtkActorCollection* theAllActors = theRenderer->GetActors();
287 theAllActors->InitTraversal();
288 vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
289 Handle(SALOME_InteractiveObject) anIObj;
290 // don't create new study object if it already exists
291 bool isDisplayed = false;
292 while(!(actor==NULL)) {
293 SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
295 if(Gactor->hasIO()) {
296 if(strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
298 anIObj = Gactor->getIO();
299 if(!anIObj.IsNull()) myRenderInter->Display(anIObj, false);
303 actor=(vtkActor*)(theAllActors->GetNextActor());
307 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
310 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
311 aStudyBuilder->Addreference(newObj1, obj);
312 // commit transaction
315 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
316 int themode = myRenderInter->GetDisplayMode();
318 vtkActorCollection* theActors =
319 GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
320 theActors->InitTraversal();
321 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
322 while(!(anActor==NULL)) {
323 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
324 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myDisplayGUI->myGeomGUI->GetFatherior(),"GEOM");
325 IO->setEntry(obj->GetID());
327 GActor->setName(theIO->getName());
329 theRenderer->AddActor(GActor);
331 anActor = (vtkActor*)theActors->GetNextActor();
335 // next item iteration
338 anAttr = SALOMEDS::GenericAttribute::_nil();
339 while(anIter->More() && anAttr->_is_nil()) {
340 SALOMEDS::SObject_var subobject = anIter->Value();
341 SALOMEDS::GenericAttribute_var aTmpAttribute;
342 if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
343 anAttr = aTmpAttribute;
351 anAttr = SALOMEDS::GenericAttribute::_nil();
356 // No viewer update should be done here!
357 //myRenderInter->Render();
358 //QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser( true );
360 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
361 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
362 SALOMEDS::GenericAttribute_var anAttr;
363 SALOMEDS::AttributeName_var aName;
364 SALOMEDS::AttributeIOR_var anIOR;
366 if(v3d->isInViewer(theIO, true)) {
367 Standard_Boolean found;
368 Handle(GEOM_AISShape) aSh = myDisplayGUI->myGeomBase->ConvertIOinGEOMAISShape(theIO, found, true);
370 ic->Display(aSh, false);
371 ic->AddOrRemoveCurrentObject(aSh, false);
376 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry());
377 if(!obj->_is_nil()) {
378 MESSAGE("BuildPresentation(): SObject not null")
379 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
380 MESSAGE("BuildPresentation(): SObject has IOR")
381 // this SObject may be GEOM module root SObject
383 bool useSubItems = false;
384 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
385 if(myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
386 while(anIter->More() && !useSubItems) {
387 SALOMEDS::SObject_var subobj = anIter->Value();
388 SALOMEDS::GenericAttribute_var aTmpAttr;
389 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
390 if(!myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
403 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
404 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
405 GEOM::GEOM_Shape_var aShape = myDisplayGUI->myGeom->GetIORFromString(anIOR->Value());
406 TopoDS_Shape Shape = myDisplayGUI->myGeomGUI->GetShapeReader().GetShape(myDisplayGUI->myGeom,aShape);
408 MESSAGE("BuildPresentation(): TopoDS_Shape is null!")
409 if(obj->FindAttribute(anAttr, "AttributeName")) {
410 MESSAGE("BuildPresentation(): SObject has Name")
411 aName = SALOMEDS::AttributeName::_narrow(anAttr);
412 // searchin for already displayed objects with the same shape
413 AIS_ListOfInteractive aDisplayed;
414 ic->DisplayedObjects(aDisplayed);
415 AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
416 Handle(AIS_Shape) anAISShape;
417 for(;anIObjects.More();anIObjects.Next()) {
418 anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
419 if(!anAISShape.IsNull()) {
420 if(anAISShape->Shape().IsSame(Shape))
422 anAISShape.Nullify();
425 if(!anAISShape.IsNull()) {
426 if(!ic->IsDisplayed(anAISShape))
427 ic->Display(anAISShape, false);
432 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
434 if (fatherSF->_is_nil())
435 MESSAGE("BuildPresentation(): fatherSF is nil!")
436 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
437 aStudyBuilder->Addreference(newObj1, obj);
438 // commit transaction
441 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
442 aSh->SetShadingColor(myDisplayGUI->myGeomBase->myShadingColor);
443 aSh->SetInfiniteState(Shape.Infinite());
444 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myDisplayGUI->myGeomGUI->GetFatherior(), "GEOM");
445 IO->setEntry(obj->GetID());
447 aSh->setName(aName->Value());
448 ic->Display(aSh, false);
450 ic->AddOrRemoveCurrentObject(aSh, false);
453 // next item iteration
456 anAttr=SALOMEDS::GenericAttribute::_nil();
457 while (anIter->More() && anAttr->_is_nil()) {
458 SALOMEDS::SObject_var subobject = anIter->Value();
459 SALOMEDS::GenericAttribute_var aTmpAttribute;
460 if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
461 anAttr = aTmpAttribute;
469 anAttr = SALOMEDS::GenericAttribute::_nil();
474 // No viewer update should be done here!
475 //QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser( true );
476 //ic->UpdateCurrentViewer();
481 //=====================================================================================
482 // function : OnDisplayAll()
484 //=====================================================================================
485 void DisplayGUI::OnDisplayAll(bool onlyPreviousDisplayedObject)
487 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
488 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
489 Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
491 //myContext->Display(v3d->getTrihedron());
493 if(!onlyPreviousDisplayedObject) {
494 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
495 SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
496 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SC);
497 for(; it->More();it->Next()) {
498 SALOMEDS::SObject_var CSO = it->Value();
499 SALOMEDS::AttributeIOR_var anIOR;
500 SALOMEDS::GenericAttribute_var anAttr;
501 if(CSO->FindAttribute(anAttr, "AttributeIOR")) {
502 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
503 Standard_Boolean testResult;
504 Handle(GEOM_AISShape) aSh = myGeomBase->ConvertIORinGEOMAISShape(anIOR->Value(), testResult);
506 myContext->Display(aSh);
508 GEOM::GEOM_Shape_ptr aShape = myGeom->GetIORFromString(anIOR->Value());
509 bool AddInSt = myGeomBase->mySettings_AddInStudy;
510 myGeomBase->mySettings_AddInStudy = false;
511 myGeomBase->Display(aShape);
512 myGeomBase->mySettings_AddInStudy = AddInSt;
518 AIS_ListOfInteractive aListDisplayedObject;
519 myContext->DisplayedObjects(aListDisplayedObject);
520 AIS_ListIteratorOfListOfInteractive ite(aListDisplayedObject);
522 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
523 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
525 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
526 if (v3d->isInViewer(GIO,true))
527 myContext->Display(aSh);
534 else if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
535 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
536 SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
537 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SC);
538 for(; it->More();it->Next()) {
539 SALOMEDS::SObject_var CSO = it->Value();
540 SALOMEDS::AttributeIOR_var anIOR;
541 SALOMEDS::GenericAttribute_var anAttr;
542 if(CSO->FindAttribute(anAttr, "AttributeIOR")) {
543 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
544 Standard_Boolean testResult;
545 GEOM_Actor* aSh = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), testResult);
547 Handle(SALOME_InteractiveObject) IObject = aSh->getIO();
548 ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->Display(IObject);
551 GEOM::GEOM_Shape_ptr aShape = myGeom->GetIORFromString(anIOR->Value());
552 bool AddInSt = myGeomBase->mySettings_AddInStudy;
553 myGeomBase->mySettings_AddInStudy = false;
554 myGeomBase->Display(aShape);
555 myGeomBase->mySettings_AddInStudy = AddInSt;
564 //=====================================================================================
565 // function : OnVTKDisplayOnly()
567 //=====================================================================================
568 void DisplayGUI::OnVTKDisplayOnly()
570 QApplication::setOverrideCursor(Qt::waitCursor);
572 // Erase all not selected actors
573 vtkRenderer* aren = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
574 vtkActorCollection* theActors = aren->GetActors();
575 theActors->InitTraversal();
576 vtkActor *ac = theActors->GetNextActor();
578 if(ac->IsA("SALOME_Actor")) {
579 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac);
580 if(!anActor->isHighlighted())
581 anActor->VisibilityOff();
583 ac = theActors->GetNextActor();
587 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
588 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
589 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
590 SALOMEDS::GenericAttribute_var anAttr;
591 SALOMEDS::AttributeName_var aName;
592 SALOMEDS::AttributeIOR_var anIOR;
594 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
595 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
597 for(;It.More();It.Next()) {
598 Handle(SALOME_InteractiveObject) IObject = It.Value();
599 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
601 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
603 if(myRenderInter->isInViewer(IObject)) {
604 myRenderInter->Display(IObject);
608 if(!obj->_is_nil()) {
609 if(!obj->FindAttribute(anAttr, "AttributeIOR"))
611 // If selected object contains displayable subobjects, then do nothing
612 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
613 SALOMEDS::GenericAttribute_var aTmpAttr;
615 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
616 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
617 if(CORBA::is_nil(aShape)) continue;
618 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
620 if(obj->FindAttribute(anAttr, "AttributeName")) {
621 aName = SALOMEDS::AttributeName::_narrow(anAttr);
623 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
626 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
627 aStudyBuilder->Addreference(newObj1, obj);
628 // commit transaction
631 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
632 int themode = myRenderInter->GetDisplayMode();
633 vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(Shape, 0, themode, Standard_True);
634 theActors->InitTraversal();
635 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
636 while(!(anActor==NULL)) {
637 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
638 GActor->setIO(IObject);
639 GActor->setName(IObject->getName());
641 theRenderer->AddActor(GActor);
642 vtkRenderWindow *renWin = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->GetRenderWindow();
644 anActor = (vtkActor*)theActors->GetNextActor();
650 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(true);
652 QApplication::restoreOverrideCursor();
657 //=====================================================================================
658 // function : OnDisplayOnly()
660 //=====================================================================================
661 void DisplayGUI::OnDisplayOnly()
663 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
666 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
667 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
668 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
670 AIS_ListOfInteractive List;
671 ic->DisplayedObjects(List);
672 AIS_ListIteratorOfListOfInteractive ite(List);
674 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
675 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
676 if (!ic->IsSelected( aSh )) {
677 ic->Erase(aSh, Standard_True, Standard_True);
683 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
684 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
686 SALOME_ListIteratorOfListIO It1(Sel->StoredIObjects());
687 for(;It1.More();It1.Next()) {
688 Handle(SALOME_InteractiveObject) IObject = It1.Value();
690 SALOMEDS::SObject_var fatherSF =
691 aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
692 if(v3d->isInViewer(IObject, true)) {
693 AIS_ListOfInteractive List1;
694 ic->ObjectsInCollector(List1);
695 AIS_ListIteratorOfListOfInteractive ite1(List1);
697 if(ite1.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
698 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite1.Value());
700 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
701 if (IObject->isSame(GIO)) {
703 ic->AddOrRemoveCurrentObject(aSh, true);
712 if (IObject->hasEntry()) {
713 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
714 SALOMEDS::GenericAttribute_var anAttr;
715 SALOMEDS::AttributeName_var aName;
716 SALOMEDS::AttributeIOR_var anIOR;
717 if (!obj->_is_nil()) {
718 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
719 // this SObject may be GEOM module root SObject
721 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
722 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
723 if(CORBA::is_nil(aShape)) continue;
724 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
726 if(obj->FindAttribute(anAttr, "AttributeName")) {
727 aName = SALOMEDS::AttributeName::_narrow(anAttr);
729 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
732 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
733 aStudyBuilder->Addreference(newObj1, obj);
734 // commit transaction
738 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
739 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myGeomGUI->GetFatherior(),"GEOM");
741 IO->setEntry(obj->GetID());
743 aSh->setName(aName->Value());
745 ic->AddOrRemoveCurrentObject(aSh, true);
754 //=====================================================================================
755 // function : OnErase()
757 //=====================================================================================
758 void DisplayGUI::OnErase()
760 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
761 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
762 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
764 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
765 Handle(SALOME_InteractiveObject) anIObject;
766 for(;It.More();It.Next()) {
767 anIObject = It.Value();
768 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
770 if(myRenderInter->isInViewer(anIObject)) {
771 myRenderInter->Erase(anIObject);
774 SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry());
775 SALOMEDS::GenericAttribute_var anAttr;
776 SALOMEDS::AttributeIOR_var anIOR;
777 if(!obj->_is_nil()) {
778 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
779 // this SObject may be GEOM module root SObject
780 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
781 bool useSubItems = false;
782 while(anIter->More() && !useSubItems) {
783 SALOMEDS::SObject_var subobj = anIter->Value();
784 SALOMEDS::GenericAttribute_var aTmpAttr;
785 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
794 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
795 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
796 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
797 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
798 if(obj->FindAttribute(anAttr, "AttributeName")) {
799 // searchin for already displayed objects with the same shape
800 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
801 vtkActorCollection* theAllActors = theRenderer->GetActors();
802 theAllActors->InitTraversal();
803 vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
804 Handle(SALOME_InteractiveObject) anIObj;
805 // don't create new study object if it already exists
806 bool isDisplayed = false;
807 while(!(actor==NULL)) {
808 SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
810 if(Gactor->hasIO()) {
811 if(strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
813 anIObj = Gactor->getIO();
815 myRenderInter->Erase(anIObj);
819 actor=(vtkActor*)(theAllActors->GetNextActor());
824 anAttr=SALOMEDS::GenericAttribute::_nil();
825 while(anIter->More() && anAttr->_is_nil()) {
826 SALOMEDS::SObject_var subobject = anIter->Value();
827 SALOMEDS::GenericAttribute_var aTmpAttribute;
828 if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
829 anAttr = aTmpAttribute;
837 anAttr = SALOMEDS::GenericAttribute::_nil();
844 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
846 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
847 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
848 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
849 Handle(SALOME_InteractiveObject) anIObject;
850 for(;It.More();It.Next()) {
851 anIObject = It.Value();
852 if(v3d->isInViewer(anIObject, true)) {
853 Standard_Boolean found;
854 Handle(GEOM_AISShape) aSh = myGeomBase->ConvertIOinGEOMAISShape(anIObject, found, true);
857 ic->AddOrRemoveCurrentObject(aSh, true);
861 SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry());
862 SALOMEDS::GenericAttribute_var anAttr;
863 SALOMEDS::AttributeIOR_var anIOR;
864 if(!obj->_is_nil()) {
865 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
866 // this SObject may be GEOM module root SObject
867 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
868 bool useSubItems = false;
869 while(anIter->More() && !useSubItems) {
870 SALOMEDS::SObject_var subobj = anIter->Value();
871 SALOMEDS::GenericAttribute_var aTmpAttr;
872 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
881 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
882 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
883 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
884 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
885 if(obj->FindAttribute(anAttr, "AttributeName")) {
886 // searchin for already displayed objects with the same shape
887 AIS_ListOfInteractive aDisplayed;
888 ic->DisplayedObjects(aDisplayed);
889 AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
890 Handle(AIS_Shape) anAISShape;
891 for(;anIObjects.More();anIObjects.Next()) {
892 anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
893 if(!anAISShape.IsNull()) {
894 if(anAISShape->Shape().IsSame(Shape))
896 anAISShape.Nullify();
899 if(!anAISShape.IsNull()) {
900 if(ic->IsDisplayed(anAISShape))
901 ic->Erase(anAISShape);
906 anAttr=SALOMEDS::GenericAttribute::_nil();
907 while(anIter->More() && anAttr->_is_nil()) {
908 SALOMEDS::SObject_var subobject = anIter->Value();
909 SALOMEDS::GenericAttribute_var aTmpAttribute;
910 if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
911 anAttr = aTmpAttribute;
919 anAttr = SALOMEDS::GenericAttribute::_nil();
926 Sel->ClearIObjects();
930 //=====================================================================================
931 // function : PrepareSubShapeSelection()
932 // purpose : (localContextId of the method is opened and defined here)
933 //=====================================================================================
934 bool DisplayGUI::PrepareSubShapeSelection(const int SubShapeType, Standard_Integer& returnLocalContextId)
936 //* Test the type of viewer */
937 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
940 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
941 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
943 /* local context opening */
944 //myGeomBase->SetDisplayedObjectList();
945 this->OnDisplayOnly();
947 returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False);
948 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
949 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
950 for(;It.More();It.Next()) {
951 Handle(SALOME_InteractiveObject) IObject = It.Value();
952 Standard_Boolean found;
953 Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(IObject, found);
954 if(found && SubShapeType >= Shape->Shape().ShapeType()) {
955 ic->Load(Shape, (8 - SubShapeType), Standard_True);
956 ic->HilightWithColor(Shape, Quantity_NOC_RED);
959 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_SUBSHAPES"));
964 //=====================================================================================
965 // function : PrepareSubShapeSelectionArgumentShape()
966 // purpose : ( localContextId of the method is opened and defined here )
967 //=====================================================================================
968 bool DisplayGUI::PrepareSubShapeSelectionArgumentShape(const TopoDS_Shape& aShape,const int SubShapeType, Standard_Integer& returnLocalContextId)
970 //* Test the type of viewer */
971 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
977 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
978 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
980 /* local context opening */
981 //myGeomBase->SetDisplayedObjectList();
982 this->OnDisplayOnly();
984 returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False) ;
986 Handle(GEOM_AISShape) Shape = new GEOM_AISShape(aShape, "");
987 ic->Display(Shape, 0, (8 - SubShapeType));
989 // Not Load(...) but Display(...)
990 // ic->Load(Shape, (8 - SubShapeType), Standard_True);
991 ic->HilightWithColor(Shape, Quantity_NOC_RED);
993 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_SUBSHAPES"));
998 //=====================================================================================
1000 //=====================================================================================
1003 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1004 {return DisplayGUI::OnGUIEvent(theCommandID, parent);}
1006 void BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
1007 {return DisplayGUI::BuildPresentation(theIO);}