// GEOM GEOMGUI : GUI for Geometry component // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // // // File : GeometryGUI.cxx // Author : Lucien PIGNOLONI // Module : GEOM // $Header$ using namespace std; #include "GeometryGUI.h" // Open CASCADE Includes #include #include #include #include // SALOME Includes #include "QAD_RightFrame.h" #include "QAD_Resource.h" #include "OCCViewer_ViewPort.h" #include "OCCViewer_ViewPort3d.h" #include "OCCViewer_Viewer3d.h" #include "VTKViewer_ViewFrame.h" #include "GEOM_AssemblyBuilder.h" #include "SALOME_ListIteratorOfListIO.hxx" #include "SALOMEGUI_ImportOperation.h" #include "GEOMBase_Tools.h" #include "GEOMBase_Sketcher.h" #include "BasicGUI.h" #include "BasicGUI_PointDlg.h" #include "PrimitiveGUI.h" #include "GenerationGUI.h" #include "BuildGUI.h" #include "BooleanGUI.h" #include "TransformationGUI.h" #include "OperationGUI.h" #include "RepairGUI.h" #include "MeasureGUI.h" /* The object itself created in the static method 'GetOrCreateGEOMBase()' */ static GEOMBase_Context* GeomGUI = 0; //======================================================================= // class : CustomItem // purpose : Set Font to a text. //======================================================================= class CustomItem : public QCustomMenuItem { public: CustomItem(const QString& s, const QFont& f) :string(s), font(f){}; ~CustomItem(){} void paint(QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h) { p->setFont(font); p->drawText(x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string); } QSize sizeHint() { return QFontMetrics(font).size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string); } private: QString string; QFont font; }; //======================================================================= // function : GeometryGUI() // purpose : Constructor //======================================================================= GeometryGUI::GeometryGUI() : QObject() { } //======================================================================= // function : ~GeometryGUI() // purpose : Destructor //======================================================================= GeometryGUI::~GeometryGUI() { } //======================================================================= // function : GetOrCreateGEOMBase() // purpose : Gets or create an object 'GEOMBase' with initialisations // : Returns 'GeomGUI' as a pointer //======================================================================= GEOMBase_Context* GeometryGUI::GetOrCreateGeometryGUI(QAD_Desktop* desktop) { GeomGUI = GeomGUI->GetOrCreateGeomGUI(desktop); return GeomGUI; } //======================================================================= // function : OnGUIEvent() [static] // purpose : manage all events on GUI //======================================================================= bool GeometryGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent) { GeometryGUI::GetOrCreateGeometryGUI(parent); QMenuBar* Mb = GeomGUI->GetDesktop()->getMainMenuBar(); bool ViewOCC; if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) ViewOCC = true; else if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) ViewOCC = false; else return false; Mb->setItemEnabled(404, ViewOCC);//Sketch Mb->setItemEnabled(405, ViewOCC);//Sketch Mb->setItemEnabled(406, ViewOCC);//Sketch Mb->setItemEnabled(603, ViewOCC);//SuppressFace Mb->setItemEnabled(604, ViewOCC);//SuppressHole Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings Mb->setItemEnabled(414, ViewOCC);// Isos Settings if (GeomGUI->GetState() == CURRENT_SKETCH && theCommandID != 404 && theCommandID != 4041 && theCommandID != 4042 && theCommandID != 4043 && theCommandID != 4044 && theCommandID != 4045 && theCommandID != 4046 && theCommandID != 4047 && theCommandID != 4048 && theCommandID != 4051 && theCommandID != 4052 && theCommandID != 4053 && theCommandID != 4061 && theCommandID != 4062 && theCommandID != 4063 && theCommandID != 4064 && theCommandID != 4065) return false; // QString theCommandID_str = itoa(theCommandID); // theCommandID_str.truncate(3); // int theCommandID_Group = theCommandID_str.toInt(); if(theCommandID == 31 || theCommandID == 33 || theCommandID == 111 || theCommandID == 112 || theCommandID == 113 || theCommandID == 121 || theCommandID == 122 || theCommandID == 123 || theCommandID == 411 || theCommandID == 412 || theCommandID == 413 || theCommandID == 414 || theCommandID == 415 || theCommandID == 804 || theCommandID == 901 || theCommandID == 903 || theCommandID == 5103 || theCommandID == 8032 || theCommandID == 8033 || theCommandID == 8034 || theCommandID == 9024) { GEOMBase_Tools* myToolsGUI = new GEOMBase_Tools(); myToolsGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 404 || theCommandID == 4041 || theCommandID == 4042 || theCommandID == 4043 || theCommandID == 4044 || theCommandID == 4045 || theCommandID == 4046 || theCommandID == 4047 || theCommandID == 4048 || theCommandID == 4051 || theCommandID == 4052 || theCommandID == 4053 || theCommandID == 4061 || theCommandID == 4062 || theCommandID == 4063 || theCommandID == 4064 || theCommandID == 4065) { GEOMBase_Sketcher* mySketcherGUI = new GEOMBase_Sketcher(); mySketcherGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 211 || theCommandID == 212 || theCommandID == 214 || theCommandID == 8021 || theCommandID == 8022 || theCommandID == 8023 || theCommandID == 9022 || theCommandID == 9023) { GEOMBase_Display* myDisplayGUI = new GEOMBase_Display(); myDisplayGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 4011 || theCommandID == 4012 || theCommandID == 4013 || theCommandID == 4014 || theCommandID == 4015 || theCommandID == 4016 || theCommandID == 4017 || theCommandID == 4018) { BasicGUI* myBasicGUI = new BasicGUI(); myBasicGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 4021 || theCommandID == 4022 || theCommandID == 4023 || theCommandID == 4024 || theCommandID == 4025) { PrimitiveGUI* myPrimitiveGUI = new PrimitiveGUI(); myPrimitiveGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 4031 || theCommandID == 4032 || theCommandID == 4033 || theCommandID == 4034) { GenerationGUI* myGenerationGUI = new GenerationGUI(); myGenerationGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 407 || theCommandID == 4081 || theCommandID == 4082 || theCommandID == 4083 || theCommandID == 4084 || theCommandID == 4085 || theCommandID == 4086) { BuildGUI* myBuildGUI = new BuildGUI(); myBuildGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 5011 || theCommandID == 5012 || theCommandID == 5013 || theCommandID == 5014) { BooleanGUI* myBooleanGUI = new BooleanGUI(); myBooleanGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 5021 || theCommandID == 5022 || theCommandID == 5023 || theCommandID == 5024 || theCommandID == 5025 || theCommandID == 5026) { TransformationGUI* myTransformationGUI = new TransformationGUI(); myTransformationGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 503 || theCommandID == 504 || theCommandID == 505 || theCommandID == 506) { OperationGUI* myOperationGUI = new OperationGUI(); myOperationGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 601 || theCommandID == 602 || theCommandID == 603 || theCommandID == 604) { RepairGUI* myRepairGUI = new RepairGUI(); myRepairGUI->OnGUIEvent(theCommandID, parent); return true; } if(theCommandID == 701 || theCommandID == 702 || theCommandID == 703 || theCommandID == 7041 || theCommandID == 7042 || theCommandID == 705 || theCommandID == 706 || theCommandID == 707) { MeasureGUI* myMeasureGUI = new MeasureGUI(); myMeasureGUI->OnGUIEvent(theCommandID, parent); return true; } return true; } //===================================================================================== // function : OnKeyPress() // purpose : [static] //===================================================================================== bool GeometryGUI::OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) { GeometryGUI::GetOrCreateGeometryGUI(parent); if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) return false; return true; } //================================================================================== // function : 0nMousePress() // purpose : [static] manage mouse events //================================================================================== bool GeometryGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) { GeometryGUI::GetOrCreateGeometryGUI(parent); if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) return false; OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort(); /* Get the clicked or selected point */ gp_Pnt thePoint; if(GeomGUI->GetState() == CURRENT_SKETCH) { GeomGUI->GetSketcher().ValidateEdge(); if(GeomGUI->GetSketcher().GetmyEdgesNumber() == 1) { QMenuBar* Mb = GeomGUI->GetDesktop()->getMainMenuBar(); QMenuData* pp; QMenuItem* item = Mb->findItem(405, &pp); pp->setItemEnabled(405, true); // SKETCH CONTRAINTS } } else if(GeomGUI->GetState() == POINT_METHOD) { GeomGUI->EraseSimulationShape(); BasicGUI_PointDlg *DialogPt = (BasicGUI_PointDlg*)(GeomGUI->GetActiveDialogBox()); if(DialogPt->UseLocalContext()) { ic->InitSelected(); if(pe->state() == Qt::ShiftButton) v3d->getAISSelector()->shiftSelect(); /* Append selection */ else v3d->getAISSelector()->select(); /* New selection */ if(ic->MoreSelected()) thePoint = BRep_Tool::Pnt( TopoDS::Vertex(ic->SelectedShape())); else thePoint = GeomGUI->ConvertClickToPoint(pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView()); } else thePoint = GeomGUI->ConvertClickToPoint(pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView()); if(DialogPt != 0) DialogPt->PointIntoCoordinates(thePoint, true); /* display point */ else GeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_ABORT")); } return false; } //======================================================================= // function : OnMouseMove() // purpose : [static] manage mouse events //======================================================================= bool GeometryGUI::OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) { GeometryGUI::GetOrCreateGeometryGUI(parent); if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) return false; OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort(); if(GeomGUI->GetState() == CURRENT_SKETCH) GeomGUI->GetSketcher().MakeCurrentEdge(pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView()); return true; } //===================================================================================== // function : SetSettings() // purpose : [static] //===================================================================================== bool GeometryGUI::SetSettings(QAD_Desktop* parent) { GeometryGUI::GetOrCreateGeometryGUI(parent); parent->menuBar()->setItemEnabled( 405, false); // SKETCH CONTRAINTS /* Shading Color */ QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed"); QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen"); QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue"); if(!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty()) GeomGUI->GetShadingColor() = Quantity_Color (SCr.toInt()/255., SCg.toInt()/255., SCb.toInt()/255., Quantity_TOC_RGB); /* Wireframe or Shading */ int DisplayMode = 0; if(parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); DisplayMode = ic->DisplayMode(); } else if(parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)parent->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); DisplayMode = myRenderInter->GetDisplayMode(); } if(DisplayMode == 1) parent->menuBar()->changeItem(211, tr("GEOM_MEN_WIREFRAME")); else parent->menuBar()->changeItem(211, tr("GEOM_MEN_SHADING")); QMenuData* pp; if(parent->menuBar()->findItem(411, &pp)) pp->removeItem(411); /* Add in Study */ QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy"); if(!AddInStudy.isEmpty()) GeomGUI->GetSettings_AddInStudy() = AddInStudy.toInt(); else GeomGUI->GetSettings_AddInStudy() = 1; parent->menuBar()->findItem(412, &pp); pp->setItemChecked(412, GeomGUI->GetSettings_AddInStudy()); /* step value */ QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep"); if(S.isEmpty()) QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100"); /* isos */ QAD_Study* ActiveStudy = parent->getActiveStudy(); int count = ActiveStudy->getStudyFramesCount(); bool ViewOCC = false; for(int i = 0; i < count; i++) { if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) { OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer(); Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU"); QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV"); if(!IsoU.isEmpty()) ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt()); if(!IsoV.isEmpty()) ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt()); ViewOCC = true; } } QMenuBar* Mb = GeomGUI->GetDesktop()->getMainMenuBar(); Mb->setItemEnabled(404, ViewOCC);//Sketch Mb->setItemEnabled(405, ViewOCC);//Sketch Mb->setItemEnabled(406, ViewOCC);//Sketch Mb->setItemEnabled(603, ViewOCC);//SuppressFace Mb->setItemEnabled(604, ViewOCC);//SuppressHole Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings Mb->setItemEnabled(414, ViewOCC);// Isos Settings return true; } //===================================================================================== // function : DefinePopup() // purpose : [static] //===================================================================================== void GeometryGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject) { GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop()); SALOME_Selection* Sel = SALOME_Selection::Selection(GeomGUI->GetActiveStudy()->getSelection()); theObject = ""; if(Sel->IObjectCount() == 1) { Handle(SALOME_InteractiveObject) IO = Sel->firstIObject(); if(IO->hasEntry()) { SALOMEDS::SObject_var sobj = GeomGUI->GetActiveStudy()->getStudyDocument()->FindObjectID(IO->getEntry()); if(!sobj->_is_nil()) { SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent(); if(strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected theObject = "Component"; } } } } if((theParent.compare("Viewer")==0)) { if(GeomGUI->GetState() == CURRENT_SKETCH) theContext = "Sketch"; else { if(Sel->IObjectCount() > 0) theContext = ""; else theContext = "NothingSelected"; } } else theContext = ""; return; } //===================================================================================== // function : CustomPopup() // purpose : [static] //===================================================================================== bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, const QString& theParent, const QString& theObject) { GeometryGUI::GetOrCreateGeometryGUI(parent); /* Deactivate any non modal dialog box to get the neutral point */ GeomGUI->EmitSignalDeactivateDialog(); Engines::Component_var comp = GeomGUI->GetDesktop()->getEngine("FactoryServer", "GEOM"); GEOM::GEOM_Gen_var myComponentGeom = GEOM::GEOM_Gen::_narrow(comp); SALOME_Selection* Sel = SALOME_Selection::Selection(GeomGUI->GetActiveStudy()->getSelection()); int nbSel = Sel->IObjectCount(); if((nbSel == 0) && (theContext.compare("Sketch")!=0)) return false; if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); if(theParent.compare("Viewer")==0) { if(theContext.compare("Sketch")==0) { SketchStatus myCS = GeomGUI->GetSketcher().GetCurrentStatus(); popup->setCheckable(TRUE); if(myCS == SEGMENT) { popup->setItemChecked(4041,true); //Sketch Segment Menu popup->setItemChecked(4042,false); //Sketch Arc Menu } else if(myCS == ARC_CHORD) { popup->setItemChecked(4041,false); //Sketch Segment Menu popup->setItemChecked(4042,true); //Sketch Arc Menu } return true; } else if(theObject.compare("Component") == 0) { popup->removeItem(QAD_DisplayOnly_Popup_ID); return true; } else { QFont f = QApplication::font(); f.setBold( TRUE ); if(nbSel==1) { Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject(); popup->removeItem(QAD_TopLabel_Popup_ID); popup->insertItem(new CustomItem (QString(IObject->getName()), f), QAD_TopLabel_Popup_ID, 0); if(IObject->hasEntry()) popup->setItemEnabled(804, false); //Add in Study Menu else popup->setItemEnabled(804, true); //Add in Study Menu if(IObject->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) { Standard_Boolean found; Handle(GEOM_AISShape) Result = GeomGUI->ConvertIOinGEOMAISShape(IObject, found, true); if(found) { if(Result->DisplayMode() == 1) popup->changeItem(8031, tr("GEOM_MEN_WIREFRAME")); //Shading/Wireframe Menu else popup->changeItem(8031, tr("GEOM_MEN_SHADING")); //Shading/Wireframe Menu } } if(!(v3d->isInViewer(IObject) && v3d->isVisible(IObject))) popup->removeItem(QAD_Erase_Popup_ID); else popup->removeItem(QAD_Display_Popup_ID); } else { popup->removeItem(QAD_DisplayOnly_Popup_ID); popup->removeItem(QAD_TopLabel_Popup_ID); popup->insertItem(new CustomItem (tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f), QAD_TopLabel_Popup_ID, 0); popup->setItemEnabled(804, false); //Add in Study Menu } } return true; } else if(theParent.compare("ObjectBrowser")==0) { popup->removeItem(QAD_TopLabel_Popup_ID); int id = popup->idAt(0); // separator if(id < 0) popup->removeItem(id); // checking for GEOM label in the selected list SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); Handle(SALOME_InteractiveObject) anIObject; bool useSubItems = false; bool needOpen = false; bool needDisplay = false; bool needErase = false; SALOMEDS::GenericAttribute_var aTmpAttr; for(;It.More();It.Next()) { anIObject = It.Value(); if(!anIObject->hasEntry()) continue; if(v3d->isInViewer(anIObject) && v3d->isVisible(anIObject)) needErase = true; else needDisplay = true; SALOMEDS::SObject_var obj = GeomGUI->GetActiveStudy()->getStudyDocument()->FindObjectID(anIObject->getEntry()); if(!obj->_is_nil()) { GEOM::GEOM_Shape_var aShape; if(obj->FindAttribute(aTmpAttr, "AttributeIOR")) { char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value(); if(str && strlen(str)) aShape = myComponentGeom->GetIORFromString(str); } else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef")) needOpen = true; if(aShape->_is_nil()) { SALOMEDS::ChildIterator_var anIter = GeomGUI->GetActiveStudy()->getStudyDocument()->NewChildIterator(obj); while(anIter->More()) { SALOMEDS::SObject_var subobj = anIter->Value(); if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { useSubItems = true; needErase = true; needDisplay = true; } else if(subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) { needOpen = true; useSubItems = true; } anIter->Next(); } } } } // remove useless popup items if(nbSel != 1) popup->removeItem(901); // rename if(useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only if(!needOpen) { int index = popup->indexOf(9024); // open popup->removeItem(9024); popup->removeItemAt(index); // separator under Open if (!needDisplay) popup->removeItem(QAD_Display_Popup_ID); if (!needErase) popup->removeItem(QAD_Erase_Popup_ID); if(!needDisplay && !needErase) { int id = popup->idAt(popup->count()-1); // last item popup->removeItem(id); // separator } } else { popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only popup->removeItem(QAD_Display_Popup_ID); popup->removeItem(QAD_Erase_Popup_ID); if (nbSel!=1) { int id = popup->idAt(popup->count()-1); // last item popup->removeItem(id); // separator } } return true; } } else if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { // MESSAGE ( " CUSTOM POPUP VIEWER VTK ") if((theParent.compare("Viewer")==0)) { popup->setItemEnabled(8034, false); //Isos Menu if(theObject.compare("Component") == 0) { popup->removeItem(QAD_DisplayOnly_Popup_ID); return true; } //int id = popup->idAt(0); QFont f = QApplication::font(); f.setBold( TRUE ); if(nbSel==1) { Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject(); popup->removeItem(QAD_TopLabel_Popup_ID); popup->insertItem(new CustomItem (QString(IObject->getName()), f), QAD_TopLabel_Popup_ID, 0); if(IObject->hasEntry()) { popup->setItemEnabled(804, false); //Add in Study Menu SALOMEDS::Study_var aStudy = GeomGUI->GetActiveStudy()->getStudyDocument(); SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry()); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeIOR_var anIOR; if(!SO->_is_nil()) { if(SO->FindAttribute(anAttr, "AttributeIOR")) { anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); Standard_Boolean found; GEOM_Actor* Result = GeomGUI->ConvertIORinGEOMActor(anIOR->Value(), found, true); if(found) { if(Result->getDisplayMode() == 1) popup->changeItem(8031, tr("GEOM_MEN_WIREFRAME")); //Shading/Wireframe Menu else popup->changeItem(8031, tr("GEOM_MEN_SHADING")); //Shading/Wireframe Menu if(!Result->GetVisibility()) popup->removeItem(QAD_Erase_Popup_ID); else popup->removeItem(QAD_Display_Popup_ID); } else popup->removeItem(QAD_Erase_Popup_ID); } } } else popup->setItemEnabled(804, true); //Add in Study Menu } else { popup->removeItem(QAD_DisplayOnly_Popup_ID); popup->removeItem(QAD_TopLabel_Popup_ID); popup->insertItem( new CustomItem (tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f), QAD_TopLabel_Popup_ID, 0); popup->setItemEnabled(804, false); //Add in Study Menu } return true; } else if(theParent.compare("ObjectBrowser")==0) { popup->removeItem(QAD_TopLabel_Popup_ID); int id = popup->idAt(0); // separator if(id < 0) popup->removeItem(id); // checking for GEOM label in the selected list SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); Handle(SALOME_InteractiveObject) anIObject; bool useSubItems = false; bool needOpen = false; bool needDisplay = false; bool needErase = false; SALOMEDS::GenericAttribute_var aTmpAttr; VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); for(;It.More();It.Next()) { anIObject = It.Value(); if(!anIObject->hasEntry()) continue; if(myRenderInter->isInViewer(anIObject) && myRenderInter->isVisible(anIObject)) needErase = true; else needDisplay = true; SALOMEDS::SObject_var obj = GeomGUI->GetActiveStudy()->getStudyDocument()->FindObjectID( anIObject->getEntry()); if(!obj->_is_nil()) { GEOM::GEOM_Shape_var aShape; if(obj->FindAttribute(aTmpAttr, "AttributeIOR")) { char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value(); if(str && strlen(str)) aShape = myComponentGeom->GetIORFromString(str); } else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef")) needOpen = true; if(aShape->_is_nil()) { SALOMEDS::ChildIterator_var anIter = GeomGUI->GetActiveStudy()->getStudyDocument()->NewChildIterator(obj); while(anIter->More()) { SALOMEDS::SObject_var subobj = anIter->Value(); if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { useSubItems = true; needDisplay = true; needErase = true; } else if(subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) { needOpen = true; useSubItems = true; } anIter->Next(); } } } } // remove useless popup items if(nbSel != 1) popup->removeItem(901); // rename if(useSubItems) popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only if(!needOpen) { int index = popup->indexOf(9024); // open popup->removeItem(9024); popup->removeItemAt(index); // separator under Open if(!needDisplay) popup->removeItem(QAD_Display_Popup_ID); if(!needErase) popup->removeItem(QAD_Erase_Popup_ID); if(!needDisplay && !needErase) { int id = popup->idAt(popup->count()-1); // last item popup->removeItem(id); // separator } } else { popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only popup->removeItem(QAD_Display_Popup_ID); popup->removeItem(QAD_Erase_Popup_ID); if(nbSel!=1) { int id = popup->idAt(popup->count()-1); // last item popup->removeItem(id); // separator } } return true; } } else { // other viewer types not supported. while(1) { int id = popup->idAt(0); if(id <= QAD_TopLabel_Popup_ID && id != -1) popup->removeItemAt(0); else break; } popup->removeItem(QAD_DisplayOnly_Popup_ID); popup->removeItem(QAD_Display_Popup_ID); popup->removeItem(QAD_Erase_Popup_ID); int id = popup->idAt(popup->count()-1); // last item if(id < 0 && id != -1) popup->removeItem(id); // separator return false; } return false; } //======================================================================= // function : activeStudyChanged() // purpose : static //======================================================================= void GeometryGUI::activeStudyChanged(QAD_Desktop* parent) { GeometryGUI::GetOrCreateGeometryGUI(parent); if(GeomGUI != 0) { if(GeomGUI->GetState() == CURRENT_SKETCH) { GeomGUI->GetSketcher().Clear(); GeomGUI->ResetState(); } QMenuBar* Mb = GeomGUI->GetDesktop()->getMainMenuBar(); bool ViewOCC = false; if(GeomGUI->GetDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) ViewOCC = true; Mb->setItemEnabled(404, ViewOCC);//Sketch Mb->setItemEnabled(405, ViewOCC);//Sketch Mb->setItemEnabled(406, ViewOCC);//Sketch Mb->setItemEnabled(603, ViewOCC);//SuppressFace Mb->setItemEnabled(604, ViewOCC);//SuppressHole Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings Mb->setItemEnabled(414, ViewOCC);// Isos Settings GeomGUI->EraseSimulationShape(); GeomGUI->EmitSignalCloseAllDialogs(); GeomGUI = 0; } return; } //======================================================================= // function : BuildPresentation() // purpose : static //======================================================================= void GeometryGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO) { GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop()); Engines::Component_var comp = GeomGUI->GetDesktop()->getEngine("FactoryServer", "GEOM"); GEOM::GEOM_Gen_var myComponentGeom = GEOM::GEOM_Gen::_narrow(comp); SALOMEDS::Study_var aStudy = GeomGUI->GetActiveStudy()->getStudyDocument(); SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); OCCViewer_Viewer3d* v3d; Handle(AIS_InteractiveContext) ic; vtkRenderer* Renderer; if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { v3d = ((OCCViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); ic = v3d->getAISContext(); } else if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { Renderer = ((VTKViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); } else return; if(theIO.IsNull()) MESSAGE("BuildPresentation(): null SALOME_InteractiveObject passed") if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { // VTK SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->entry()); SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry()); VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeName_var aName; SALOMEDS::AttributeIOR_var anIOR; if(myRenderInter->isInViewer(theIO)) { myRenderInter->Display(theIO, false); } else { // Create new actor if(!obj->_is_nil()) { if(obj->FindAttribute(anAttr, "AttributeIOR")) { // this SObject may be GEOM module root SObject bool useSubItems = false; SALOMEDS::ChildIterator_var anIter = GeomGUI->GetActiveStudy()->getStudyDocument()->NewChildIterator(obj); if(myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) { while (anIter->More() && !useSubItems) { SALOMEDS::SObject_var subobj = anIter->Value(); SALOMEDS::GenericAttribute_var aTmpAttr; if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { if (!myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) { anAttr = aTmpAttr; obj = subobj; useSubItems = true; } else anIter->Next(); } else anIter->Next(); } } while(useSubItems?anIter->More():!anAttr->_is_nil()) { anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString(anIOR->Value()); TopoDS_Shape Shape = GeomGUI->GetShapeReader().GetShape(myComponentGeom,aShape); if(obj->FindAttribute(anAttr, "AttributeName")) { aName = SALOMEDS::AttributeName::_narrow(anAttr); vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); vtkActorCollection* theAllActors = theRenderer->GetActors(); theAllActors->InitTraversal(); vtkActor* actor = (vtkActor*)theAllActors->GetNextActor(); Handle(SALOME_InteractiveObject) anIObj; // don't create new study object if it already exists bool isDisplayed = false; while(!(actor==NULL)) { SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor); if(Gactor!=NULL) { if(Gactor->hasIO()) { if(strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) { isDisplayed = true; anIObj = Gactor->getIO(); if(!anIObj.IsNull()) myRenderInter->Display(anIObj, false); } } } actor=(vtkActor*)(theAllActors->GetNextActor()); } if(!isDisplayed) { // open transaction QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->GetActiveStudy() ); op->start(); SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); aStudyBuilder->Addreference(newObj1, obj); // commit transaction op->finish(); vtkRenderWindow *renWin = theRenderer->GetRenderWindow(); int themode = myRenderInter->GetDisplayMode(); vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True); theActors->InitTraversal(); vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); while(!(anActor==NULL)) { GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor); Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), GeomGUI->GetFatherior(),"GEOM"); IO->setEntry(obj->GetID()); GActor->setIO(IO); GActor->setName(theIO->getName()); theRenderer->AddActor(GActor); // renWin->Render(); anActor = (vtkActor*)theActors->GetNextActor(); } } } // next item iteration if(useSubItems) { anIter->Next(); anAttr = SALOMEDS::GenericAttribute::_nil(); while(anIter->More() && anAttr->_is_nil()) { SALOMEDS::SObject_var subobject = anIter->Value(); SALOMEDS::GenericAttribute_var aTmpAttribute; if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { anAttr = aTmpAttribute; obj = subobject; } else anIter->Next(); } } else anAttr = SALOMEDS::GenericAttribute::_nil(); } } } } // No viewer update should be done here! //myRenderInter->Render(); //GeomGUI->GetActiveStudy()->updateObjBrowser( true ); } else if(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(GeomGUI->GetActiveStudy()->getActiveStudyFrame()->entry()); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeName_var aName; SALOMEDS::AttributeIOR_var anIOR; if(v3d->isInViewer(theIO, true)) { Standard_Boolean found; Handle(GEOM_AISShape) aSh = GeomGUI->ConvertIOinGEOMAISShape(theIO, found, true); if(found) { ic->Display(aSh, false); ic->AddOrRemoveCurrentObject(aSh, false); } } else { SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry()); if(!obj->_is_nil()) { MESSAGE("BuildPresentation(): SObject not null") if(obj->FindAttribute(anAttr, "AttributeIOR")) { MESSAGE("BuildPresentation(): SObject has IOR") // this SObject may be GEOM module root SObject bool useSubItems = false; SALOMEDS::ChildIterator_var anIter = GeomGUI->GetActiveStudy()->getStudyDocument()->NewChildIterator(obj); if(myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) { while(anIter->More() && !useSubItems) { SALOMEDS::SObject_var subobj = anIter->Value(); SALOMEDS::GenericAttribute_var aTmpAttr; if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { if(!myComponentGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) { anAttr = aTmpAttr; obj = subobj; useSubItems = true; } else anIter->Next(); } else anIter->Next(); } } while(useSubItems?anIter->More():!anAttr->_is_nil()) { anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString(anIOR->Value()); TopoDS_Shape Shape = GeomGUI->GetShapeReader().GetShape(myComponentGeom,aShape); if(Shape.IsNull()) MESSAGE("BuildPresentation(): TopoDS_Shape is null!") if(obj->FindAttribute(anAttr, "AttributeName")) { MESSAGE("BuildPresentation(): SObject has Name") aName = SALOMEDS::AttributeName::_narrow(anAttr); // searchin for already displayed objects with the same shape AIS_ListOfInteractive aDisplayed; ic->DisplayedObjects(aDisplayed); AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed); Handle(AIS_Shape) anAISShape; for(;anIObjects.More();anIObjects.Next()) { anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value()); if(!anAISShape.IsNull()) { if(anAISShape->Shape().IsSame(Shape)) break; anAISShape.Nullify(); } } if(!anAISShape.IsNull()) { if(!ic->IsDisplayed(anAISShape)) ic->Display(anAISShape, false); } else { if(!useSubItems) { // open transaction QAD_Operation* op = new SALOMEGUI_ImportOperation( GeomGUI->GetActiveStudy() ); op->start(); if (fatherSF->_is_nil()) MESSAGE("BuildPresentation(): fatherSF is nil!") SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); aStudyBuilder->Addreference(newObj1, obj); // commit transaction op->finish(); } Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value()); aSh->SetShadingColor(GeomGUI->GetShadingColor()); Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), GeomGUI->GetFatherior(), "GEOM"); IO->setEntry(obj->GetID()); aSh->setIO(IO); aSh->setName(aName->Value()); ic->Display(aSh, false); if(!useSubItems) ic->AddOrRemoveCurrentObject(aSh, false); } } // next item iteration if(useSubItems) { anIter->Next(); anAttr=SALOMEDS::GenericAttribute::_nil(); while (anIter->More() && anAttr->_is_nil()) { SALOMEDS::SObject_var subobject = anIter->Value(); SALOMEDS::GenericAttribute_var aTmpAttribute; if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { anAttr = aTmpAttribute; obj = subobject; } else anIter->Next(); } } else anAttr = SALOMEDS::GenericAttribute::_nil(); } } } } // No viewer update should be done here! //GeomGUI->GetActiveStudy()->updateObjBrowser( true ); //ic->UpdateCurrentViewer(); } } //===================================================================================== // EXPORTED METHODS //===================================================================================== extern "C" { bool OnGUIEvent(int theCommandID, QAD_Desktop* parent) {return GeometryGUI::OnGUIEvent(theCommandID, parent);} bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) {return GeometryGUI::OnKeyPress(pe, parent, studyFrame);} bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) {return GeometryGUI::OnMousePress(pe, parent, studyFrame);} bool OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) {return GeometryGUI::OnMouseMove(pe, parent, studyFrame);} bool SetSettings(QAD_Desktop* parent) {return GeometryGUI::SetSettings(parent);} bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, const QString & theParent, const QString & theObject) {return GeometryGUI::CustomPopup(parent, popup, theContext, theParent, theObject);} void definePopup(QString & theContext, QString & parent, QString & theObject) {GeometryGUI::DefinePopup(theContext, parent, theObject);} bool activeStudyChanged(QAD_Desktop* parent) {GeometryGUI::activeStudyChanged(parent);} void buildPresentation(const Handle(SALOME_InteractiveObject)& theIO) {GeometryGUI::BuildPresentation(theIO);} void supportedViewType(int* buffer, int bufferSize) { if(!buffer || !bufferSize) return; buffer[0] = (int)VIEW_OCC; if (--bufferSize) buffer[1] = (int)VIEW_VTK; } }