X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMBase%2FGEOMBase.cxx;h=7ab1fa15263328c61026fd9020bfd205c2e33959;hb=bbafce4b04731f9219f75dc124ec2429d994c202;hp=438a1e541e7eaa161dc87734f7e5bec2466a2e93;hpb=c577ca78d7a6e286526662cf54df6de1f4f2f449;p=modules%2Fgeom.git diff --git a/src/GEOMBase/GEOMBase.cxx b/src/GEOMBase/GEOMBase.cxx index 438a1e541..7ab1fa152 100644 --- a/src/GEOMBase/GEOMBase.cxx +++ b/src/GEOMBase/GEOMBase.cxx @@ -1,50 +1,53 @@ -// GEOM GEOMGUI : GUI for Geometry component +// Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE // -// 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 +// Copyright (C) 2003-2007 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, or (at your option) any later version. // +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// File : GEOMBase.cxx -// Author : Damien COQUERET -// Module : GEOM -// $Header: -using namespace std; +// GEOM GEOMGUI : GUI for Geometry component +// File : GEOMBase.cxx +// Author : Damien COQUERET, Open CASCADE S.A.S. +// #include "GEOMBase.h" -//// SALOME Includes -# include "Utils_ORB_INIT.hxx" -# include "Utils_SINGLETON.hxx" - -#include "QAD_RightFrame.h" -#include "QAD_MessageBox.h" -#include "QAD_Resource.h" +#include +#include -#include "GEOM_AssemblyBuilder.h" -#include "VTKViewer_ViewFrame.h" -#include "OCCViewer_ViewPort3d.h" -#include "OCCViewer_Viewer3d.h" - -#include "SALOME_ListIteratorOfListIO.hxx" -#include "SALOMEGUI_ImportOperation.h" -#include "SALOMEGUI_NameDlg.h" +//// SALOME Includes +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include // // Open CASCADE Includes #include @@ -52,789 +55,47 @@ using namespace std; #include #include -#include #include +#include #include #include -#include -#include -#include -#include -#include +#include +#include #include -// // QT Includes -#include - -#include "GEOMBase_aParameterDlg.h" - -//================================================================================= -// 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 : GEOMBase() -// purpose : Constructor -//======================================================================= -GEOMBase::GEOMBase() : - QObject() -{ - myGeomGUI = GEOMContext::GetGeomGUI(); - myGeom = myGeomGUI->myComponentGeom; - - /* 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()) - myShadingColor = Quantity_Color(SCr.toInt()/255., SCg.toInt()/255., SCb.toInt()/255., Quantity_TOC_RGB); - else - myShadingColor = Quantity_Color(Quantity_NOC_GOLDENROD); - - QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy"); - if(!AddInStudy.isEmpty()) - mySettings_AddInStudy = AddInStudy.toInt(); - else - mySettings_AddInStudy = 1; -} - - -//======================================================================= -// function : ~GEOMBase() -// purpose : Destructor -//======================================================================= -GEOMBase::~GEOMBase() -{ -} - - -//================================================================================= -// function : CustomPopup() -// purpose : [static] -//================================================================================= -bool GEOMBase::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext, - const QString& theParent, const QString& theObject) -{ - GEOMBase* myGeomBase = new GEOMBase(); - QAD_Study* ActiveStudy = parent->getActiveStudy(); - - /* Deactivate any non modal dialog box to get the neutral point */ - myGeomBase->myGeomGUI->EmitSignalDeactivateDialog(); - - SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection()); - int nbSel = Sel->IObjectCount(); - - if((nbSel == 0)) - return false; - - if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - if(theParent.compare("Viewer") == 0) { - 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 = myGeomBase->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 = ActiveStudy->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 = myGeomBase->myGeom->GetIORFromString(str); - } - else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef")) - needOpen = true; - - if(aShape->_is_nil()) { - SALOMEDS::ChildIterator_var anIter = ActiveStudy->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(ActiveStudy->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 = ActiveStudy->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 = myGeomBase->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*)ActiveStudy->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 = ActiveStudy->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 = myGeomBase->myGeom->GetIORFromString(str); - } - else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef")) - needOpen = true; - - if(aShape->_is_nil()) { - SALOMEDS::ChildIterator_var anIter = ActiveStudy->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 : Display() -// purpose : Displays a CORBA shape -//===================================================================================== -bool GEOMBase::Display(GEOM::GEOM_Shape_ptr aShape, Standard_CString name) -{ - // MESSAGE ( "GEOMBase::Display init ") - Handle(GEOM_InteractiveObject) IO; - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - Sel->ClearIObjects(); - - if(aShape->_is_nil()) { - QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_PRP_ABORT"), tr("GEOM_BUT_OK")); - return false; - } - - TopoDS_Shape shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape); - if(shape.IsNull()) - return false; - - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributePixMap_var aPixmap; - - SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM"); - int aLocked = false; - if(father->_is_nil()) { - QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy()); - op->start(); - aLocked = aStudy->GetProperties()->IsLocked(); - if(aLocked) - aStudy->GetProperties()->SetLocked(false); - father = aStudyBuilder->NewComponent("GEOM"); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(QAD_Application::getDesktop()->getComponentUserName("GEOM")); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixmap->SetPixMap("ICON_OBJBROWSER_Geometry"); - QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(); - if(aLocked) - aStudy->GetProperties()->SetLocked(true); - op->finish(); - } - - aStudyBuilder->DefineComponentInstance(father, myGeom); - father->ComponentIOR(myGeomGUI->GetFatherior()); - - TCollection_AsciiString nameG(""); - Standard_CString Type; - if(TCollection_AsciiString(name).IsEqual(Standard_CString(""))) { - if(TCollection_AsciiString(aShape->NameType()).IsEqual(Standard_CString(""))) { - Standard_CString type; - GetShapeTypeString(shape,type); - aShape->NameType(type); - nameG += TCollection_AsciiString(type) + TCollection_AsciiString("_") + TCollection_AsciiString(myGeomGUI->GetNbGeom()++) + TCollection_AsciiString("\0"); - } - else - nameG += TCollection_AsciiString(aShape->NameType()) + TCollection_AsciiString("_") + TCollection_AsciiString(myGeomGUI->GetNbGeom()++) + TCollection_AsciiString("\0"); - } - else - nameG = TCollection_AsciiString(name); - - // VTK - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - int themode = myRenderInter->GetDisplayMode(); - - vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(shape, 0, themode, Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - - IO = new GEOM_InteractiveObject(aShape->Name(), myGeomGUI->GetFatherior(), "GEOM"); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor); - GActor->setIO(IO); - GActor->setName(nameG.ToCString()); - - theRenderer->AddActor(GActor); - anActor = (vtkActor*)theActors->GetNextActor(); - } - } - // OCC - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - Handle(GEOM_AISShape) theResult = new GEOM_AISShape(shape, nameG.ToCString()); - theResult->SetShadingColor(myShadingColor); - IO = new GEOM_InteractiveObject(aShape->Name(), myGeomGUI->GetFatherior(), "GEOM"); - theResult->setIO(IO); - theResult->setName(nameG.ToCString()); - - /* Precaution : close any local context to permit the display */ - if(ic->HasOpenedContext()) - ic->CloseAllContexts(); - - ic->Display(theResult); - } - - // DCQ Sel->AddIObject(IO, false); - QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint(); - if(mySettings_AddInStudy) - AddInStudy(false, IO); - - return true; -} - - -//===================================================================================== -// function : AddInStudy() -// purpose : anIOShape or a selected shape -//===================================================================================== -bool GEOMBase::AddInStudy(bool selection, const Handle(SALOME_InteractiveObject)& anIO) -{ - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - if (!(!mySettings_AddInStudy || selection)) { - Sel->ClearIObjects(); - } - - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributePixMap_var aPixmap; - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::AttributeSelectable_var aSelAttr; - - SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM"); - int aLocked = false; - if(father->_is_nil()) { - QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy()); - op->start(); - aLocked = aStudy->GetProperties()->IsLocked(); - if(aLocked) - aStudy->GetProperties()->SetLocked(false); - father = aStudyBuilder->NewComponent("GEOM"); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue( QAD_Application::getDesktop()->getComponentUserName("GEOM")); - anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixmap->SetPixMap("ICON_OBJBROWSER_Geometry"); - if (aLocked) - aStudy->GetProperties()->SetLocked(true); - op->finish(); - } - - aStudyBuilder->DefineComponentInstance(father, myGeom); - father->ComponentIOR(myGeomGUI->GetFatherior()); - - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry()); - - Handle(GEOM_AISShape) GAISShape; - GEOM_Actor* GActor; - Handle(GEOM_InteractiveObject) GIO; - bool found = false; - - // VTK - if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - vtkRenderer *Renderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - - vtkActorCollection* theActors = Renderer->GetActors(); - theActors->InitTraversal(); - vtkActor *ac = theActors->GetNextActor(); - while(!(ac==NULL)) { - if(ac->IsA("GEOM_Actor")) { - GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac); - if(anActor->hasIO()) { - Handle(SALOME_InteractiveObject) IO = anActor->getIO(); - if(IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) { - GIO = Handle(GEOM_InteractiveObject)::DownCast(IO); - if(anIO->isSame(GIO)) { - found = true; - GActor = anActor; - break; - } - } - } - } - ac = theActors->GetNextActor(); - } - - if(!found) - return false; - } - // OCC - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListIteratorOfListOfInteractive ite(List); - while(ite.More()) { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if(aSh->hasIO()) { - Handle(SALOME_InteractiveObject) IO = aSh->getIO(); - if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) { - GIO = Handle(GEOM_InteractiveObject)::DownCast(IO); - if(anIO->isSame(GIO)) { - found = true; - GAISShape = aSh; - break; - } - } - } - } - ite.Next(); - } - - if(!found) - return false; - } - - if(!mySettings_AddInStudy || selection) { - QString Name = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), anIO->getName()); - if(!Name.isEmpty()) { - // VTK - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) - GActor->setName(strdup(Name.latin1())); - // OCC - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) - GAISShape->setName(strdup(Name.latin1())); - } - else - return false; - } - - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy()); - op->start(); - - SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father); - - GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(GIO->getIOR()); - - /* For the shape inserted into the study we set its field 'studyshapeid' */ - /* so the shape will contain its corresponding entry in the study Ocaf doc. */ - aShape->StudyShapeId(newObj->GetID()); - - GIO->setEntry(newObj->GetID()); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR->SetValue(aShape->Name()); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - - anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - if(aShape->ShapeType() == GEOM::COMPOUND) - aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND"); - else if(aShape->ShapeType() == GEOM::COMPSOLID) - aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID"); - else if(aShape->ShapeType() == GEOM::SOLID) - aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID"); - else if(aShape->ShapeType() == GEOM::SHELL) - aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL"); - else if(aShape->ShapeType() == GEOM::FACE) - aPixmap->SetPixMap("ICON_OBJBROWSER_FACE"); - else if(aShape->ShapeType() == GEOM::WIRE) - aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE"); - else if(aShape->ShapeType() == GEOM::EDGE) - aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE"); - else if(aShape->ShapeType() == GEOM::VERTEX) - aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX"); - - // VTK - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - GActor->setIO(GIO); - aName->SetValue(GActor->getName()); - } - // OCC - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - GAISShape->setIO(GIO); - aName->SetValue(GAISShape->getName()); - } - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1,newObj); - - GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR; - listIOR = myGeom->GetReferencedObjects(aShape); - - if(listIOR->length()>0) { - SALOMEDS::SObject_var Arguments = aStudyBuilder->NewObject(newObj); - anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(tr("GEOM_ARGUMENTS")); - anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeSelectable"); - aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); - aSelAttr->SetSelectable(false); - - bool ObjectReferenced = false; - for (unsigned int ind = 0; ind < listIOR->length();ind++) { - SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(listIOR[ind]); - - if(!theObj->_is_nil()) { - SALOMEDS::SObject_var RefObject = aStudyBuilder->NewObject(Arguments); - aStudyBuilder->Addreference(RefObject, theObj); - ObjectReferenced = true; - } - } - - if(!ObjectReferenced) - aStudyBuilder->RemoveObject(Arguments); - } - op->finish(); - - if(!mySettings_AddInStudy || selection) - QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(); - else { - QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(false); - // DCQ Sel->AddIObject(GIO); - } - return true; -} +#include +#include //===================================================================================== // function : GetShapeFromIOR() -// purpose : exist also as static method ! +// purpose : Get shape data by the specified IOR //===================================================================================== -TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR) +TopoDS_Shape GEOMBase::GetShapeFromIOR( const QString& IOR ) { - TopoDS_Shape result; - if(IOR.stripWhiteSpace().isEmpty()) - return result; - ORB_INIT &init = *SINGLETON_::Instance(); - CORBA::ORB_var& _orb = init.orb() ; - CORBA::Object_var obj = _orb->string_to_object((char*)(IOR.latin1())); - if(CORBA::is_nil(obj)) - return result; - GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(IOR); - if(!aShape->_is_nil()) - result = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape); - return result; + GEOM::GEOM_Object_var geomObj = GEOMBase::GetObjectFromIOR( IOR ); + TopoDS_Shape shape; + GetShape( geomObj, shape, TopAbs_SHAPE ); + return shape; } //===================================================================================== // function : GetIndex() -// purpose : Get the index of a sub shape in a main shape : index start at 1 +// purpose : Get the index of a sub-shape in a main shape : index start at 1 //===================================================================================== -int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/) -{ - if(shape.IsNull() || subshape.IsNull()) - return -1; - - int index = 1; - if(subshape.ShapeType() == TopAbs_COMPOUND) { - TopoDS_Iterator it; - TopTools_ListOfShape CL; - CL.Append(shape); - TopTools_ListIteratorOfListOfShape itC; - for(itC.Initialize(CL); itC.More(); itC.Next()) { - for(it.Initialize(itC.Value()); it.More(); it.Next()) { - if(it.Value().ShapeType() == TopAbs_COMPOUND) { - if(it.Value().IsSame(subshape)) - return index; - else - index++; - CL.Append(it.Value()); - } - } - } +int GEOMBase::GetIndex( const TopoDS_Shape& subshape, const TopoDS_Shape& shape ) +{ + int idx = -1; + if ( !shape.IsNull() && !subshape.IsNull() ) { + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes( shape, anIndices ); + if ( anIndices.Contains( subshape ) ) + idx = anIndices.FindIndex( subshape ); } - else { - TopExp_Explorer Exp(shape, subshape.ShapeType()); - TopTools_MapOfShape M; - while(Exp.More()) { - if(M.Add(Exp.Current())) { - if(Exp.Current().IsSame(subshape)) - return index; - index++; - } - Exp.Next(); - } - } - return -1; + return idx; } @@ -842,59 +103,63 @@ int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, // function : GetTopoFromSelection() // purpose : Define tds from a single selection and retuen true //======================================================================= -bool GEOMBase::GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds) +TopoDS_Shape GEOMBase::GetTopoFromSelection( const SALOME_ListIO& IObjects ) { - if(Sel->IObjectCount() != 1) - return false; - - Handle(SALOME_InteractiveObject) IO = Sel->firstIObject(); - /* case SObject */ - if(IO->hasEntry()) { - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if(!obj->_is_nil()) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - tds = this->GetShapeFromIOR(anIOR->Value()); - if(tds.IsNull()) - return false; - else - return true; + TopoDS_Shape shape; + if ( IObjects.Extent() == 1 ){ + Handle(SALOME_InteractiveObject) IO = IObjects.First(); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( IO->hasEntry() && study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectID( IO->getEntry() ) ); + _PTR(GenericAttribute) anAttr; + if ( obj && obj->FindAttribute( anAttr, "AttributeIOR" ) ) { + _PTR(AttributeIOR) anIOR( anAttr ); + shape = GetShapeFromIOR( anIOR->Value().c_str() ); } } } - - if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) { - Standard_CString ior = ""; - Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO); - ior = GIObject->getIOR(); - tds = this->GetShapeFromIOR(ior); - if(tds.IsNull()) - return false; - else - return true; - } - - return false; + return shape; } - //======================================================================= // function : GetNameOfSelectedIObjects() // purpose : Define the name geom++ or other name of mono or multi sel. //======================================================================= -int GEOMBase::GetNameOfSelectedIObjects(SALOME_Selection* Sel, QString& aName) +int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& IObjects, + QString& name, + const bool shapesOnly ) { - int nbSel = Sel->IObjectCount(); - if(nbSel == 1) { - Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject(); - aName = IObject->getName(); - } + int nbSel = 0; + name = ""; // clear output name + + if ( !shapesOnly ) { + nbSel = IObjects.Extent(); + if ( nbSel == 1 ) { + Handle(SALOME_InteractiveObject) anIObj = IObjects.First(); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( anIObj->hasEntry() && study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectID( anIObj->getEntry() ) ); + _PTR(GenericAttribute) anAttr; + if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) { + _PTR(AttributeName) aNameAttr ( anAttr ); + name = aNameAttr->Value().c_str(); + } + } + } + } else { - aName = tr("%1_objects").arg(nbSel); + GEOM::ListOfGO anObjs; + ConvertListOfIOInListOfGO( IObjects, anObjs, shapesOnly ); + nbSel = anObjs.length(); + if ( nbSel == 1 ) + name = GetName( anObjs[ 0 ] ); } + + if ( nbSel > 1 ) + name = QObject::tr( "%1_objects" ).arg( nbSel ); + return nbSel; } @@ -903,101 +168,113 @@ int GEOMBase::GetNameOfSelectedIObjects(SALOME_Selection* Sel, QString& aName) // function : GetShapeTypeString() // purpose : for a single shape //================================================================================= -bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString) +QString GEOMBase::GetShapeTypeString(const TopoDS_Shape& shape) { - if(aShape.IsNull()) { - aTypeString = "aNullShape"; - return false; - } - switch(aShape.ShapeType()) - { + QString aTypeString; + if ( !shape.IsNull() ) { + switch ( shape.ShapeType() ) { case TopAbs_COMPOUND: { - aTypeString = strdup(tr("GEOM_COMPOUND")); - return true; + aTypeString = QObject::tr( "GEOM_COMPOUND" ); + break; } - case TopAbs_COMPSOLID: + case TopAbs_COMPSOLID: { - aTypeString = strdup(tr("GEOM_COMPOUNDSOLID")) ; - return true ; + aTypeString = QObject::tr( "GEOM_COMPOUNDSOLID" ); + break; } case TopAbs_SOLID: { - aTypeString = strdup(tr("GEOM_SOLID")) ; - return true ; + aTypeString = QObject::tr( "GEOM_SOLID" ); + break; } case TopAbs_SHELL: { - aTypeString = strdup(tr("GEOM_SHELL")) ; - return true ; + aTypeString = QObject::tr( "GEOM_SHELL" ); + break; } case TopAbs_FACE: - { - BRepAdaptor_Surface surf(TopoDS::Face(aShape)); - if(surf.GetType() == GeomAbs_Plane) { - aTypeString = strdup(tr("GEOM_PLANE")); - return true; - } - else if(surf.GetType() == GeomAbs_Cylinder) { - aTypeString = strdup(tr("GEOM_SURFCYLINDER")); - return true; - } - else if(surf.GetType() == GeomAbs_Sphere) { - aTypeString = strdup(tr("GEOM_SURFSPHERE")); - return true ; - } - else if(surf.GetType() == GeomAbs_Torus) { - aTypeString = strdup(tr("GEOM_SURFTORUS")); - return true ; - } - else if(surf.GetType() == GeomAbs_Cone) { - aTypeString = strdup(tr("GEOM_SURFCONE")); - return true ; - } - else { - aTypeString = strdup(tr("GEOM_FACE")); - return true; - } + { + BRepAdaptor_Surface surf( TopoDS::Face( shape ) ); + switch ( surf.GetType() ) { + case GeomAbs_Plane: + { + aTypeString = QObject::tr( "GEOM_PLANE" ); + break; + } + case GeomAbs_Cylinder: + { + aTypeString = QObject::tr( "GEOM_SURFCYLINDER" ); + break; + } + case GeomAbs_Sphere: + { + aTypeString = QObject::tr( "GEOM_SURFSPHERE" ); + break; + } + case GeomAbs_Torus: + { + aTypeString = QObject::tr( "GEOM_SURFTORUS" ); + break; + } + case GeomAbs_Cone: + { + aTypeString = QObject::tr( "GEOM_SURFCONE" ); + break; + } + default: + { + aTypeString = QObject::tr( "GEOM_FACE" ); + break; + } + } + break; } case TopAbs_WIRE: { - aTypeString = strdup(tr("GEOM_WIRE")); - return true; + aTypeString = QObject::tr( "GEOM_WIRE" ); + break; } case TopAbs_EDGE: { - BRepAdaptor_Curve curv(TopoDS::Edge(aShape)); - if(curv.GetType() == GeomAbs_Line) { - if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6)) - aTypeString = strdup(tr("GEOM_LINE")); - else - aTypeString = strdup(tr("GEOM_EDGE")); - return true; - } - else if(curv.GetType() == GeomAbs_Circle) { - if(curv.IsClosed()) - aTypeString = strdup(tr("GEOM_CIRCLE")); - else - aTypeString = strdup(tr("GEOM_ARC")); - return true; - } - else { - aTypeString = strdup(tr("GEOM_EDGE")); - return true; - } + BRepAdaptor_Curve curv( TopoDS::Edge( shape ) ); + switch ( curv.GetType() ) { + case GeomAbs_Line: + { + aTypeString = ( qAbs( curv.FirstParameter() ) >= 1E6 || qAbs( curv.LastParameter() ) >= 1E6 ) ? + QObject::tr( "GEOM_LINE" ) : QObject::tr( "GEOM_EDGE" ); + break; + } + case GeomAbs_Circle: + { + aTypeString = curv.IsClosed() ? QObject::tr( "GEOM_CIRCLE" ) : QObject::tr( "GEOM_ARC" ); + break; + } + default: + { + aTypeString = QObject::tr( "GEOM_EDGE" ); + break; + } + } + break; } case TopAbs_VERTEX: { - aTypeString = strdup(tr("GEOM_VERTEX")); - return true; + aTypeString = QObject::tr( "GEOM_VERTEX" ); + break; } case TopAbs_SHAPE: { - aTypeString = strdup(tr("GEOM_SHAPE")); - return true; + aTypeString = QObject::tr( "GEOM_SHAPE" ); + break; + } + default: + { + break; } } - return false; + } + return aTypeString; } @@ -1005,51 +282,44 @@ bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& // function : ConvertIORinGEOMAISShape() // purpose : //======================================================================= -Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView) +Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const QString& IOR, bool onlyInActiveView) { - Handle(GEOM_AISShape) resultShape; - testResult = false; - int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount(); - for(int i = 0; i < nbSf; i++) { - QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i); - if(sf->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while(ite.More()) { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if(aSh->hasIO()) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - Standard_CString theIOR = GIO->getIOR(); - if(strcmp(IOR, theIOR) == 0) { - if(onlyInActiveView) { - if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) { - testResult = true; - resultShape = aSh; - return resultShape; - } - } - else { - testResult = true; - resultShape = aSh; - return resultShape; - } - } - } - } - ite.Next(); - } + Handle(GEOM_AISShape) shape; + + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) ); + if ( obj ) { + QList views; + if ( onlyInActiveView ) + views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() ); + else + views = SUIT_Session::session()->activeApplication()->desktop()->windows(); + foreach ( SUIT_ViewWindow* view, views ) { + if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) { + Handle(AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)view->getViewManager()->getViewModel())->getAISContext(); + + AIS_ListOfInteractive displayed; + ic->DisplayedObjects( displayed ); + AIS_ListIteratorOfListOfInteractive it( displayed ); + while ( it.More() && shape.IsNull() ) { + if ( it.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) { + Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() ); + if ( !sh.IsNull() && sh->hasIO() ) { + Handle(SALOME_InteractiveObject) IO = sh->getIO(); + if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() ) + shape = sh; + } + } + it.Next(); + } + } + if ( !shape.IsNull() ) break; + } } } - return resultShape; + return shape; } @@ -1057,289 +327,211 @@ Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Stand // function : ConvertIORinGEOMActor() // purpose : //======================================================================= -GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView) +GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const QString& IOR, bool onlyInActiveView) { - int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount(); - for(int i = 0; i < nbSf; i++) { - QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i); - if(sf->getTypeView() == VIEW_VTK) { - vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theActors = Renderer->GetActors(); - theActors->InitTraversal(); - vtkActor *ac = theActors->GetNextActor(); - while(!(ac==NULL)) { - if( ac->IsA("GEOM_Actor")) { - GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac); - if(anActor->hasIO()) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(anActor->getIO()); - Standard_CString theIOR = GIO->getIOR(); - if(strcmp(IOR, theIOR) == 0) { - if(onlyInActiveView) { - if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) { - testResult = true; - return anActor; - } - } - else { - testResult = true; - return anActor; - } - } - } - } - ac = theActors->GetNextActor(); + GEOM_Actor* actor = 0; + + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) ); + if ( obj ) { + QList views; + if ( onlyInActiveView ) + views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() ); + else + views = SUIT_Session::session()->activeApplication()->desktop()->windows(); + foreach ( SUIT_ViewWindow* view, views ) { + if ( view && view->getViewManager()->getType() == SVTK_Viewer::Type() ) { + SVTK_ViewWindow* aVTKViewWindow = dynamic_cast( view ); + if( !aVTKViewWindow ) + continue; + vtkRenderer* Renderer = aVTKViewWindow->getRenderer(); + vtkActorCollection* theActors = Renderer->GetActors(); + theActors->InitTraversal(); + vtkActor* a = theActors->GetNextActor(); + while( a && !actor ) { + if ( a->IsA( "GEOM_Actor" ) ) { + GEOM_Actor* ga = GEOM_Actor::SafeDownCast( a ); + if ( ga && ga->hasIO() ) { + Handle(SALOME_InteractiveObject) IO = ga->getIO(); + if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() ) + actor = ga; + } + } + a = theActors->GetNextActor(); + } + } + if ( actor ) break; } } } - testResult = false; - return GEOM_Actor::New(); + return actor; } - //======================================================================= -// function : ConvertIOinGEOMAISShape() +// function : GetAIS() // purpose : //======================================================================= -Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView) +Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& IO, + bool onlyInActiveView, bool /*onlyGeom*/ ) { - Handle(GEOM_AISShape) res; - int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount(); - for(int i = 0; i < nbSf; i++) { - QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i); - if(sf->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while(ite.More()) { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if(aSh->hasIO()) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - if(GIO->isSame(IO)) { - if(onlyInActiveView) { - if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) { - testResult = true; - return aSh; - } - } - else { - testResult = true; - return aSh; - } - } - } - } - ite.Next(); - } - } + Handle(AIS_InteractiveObject) aisObject; + + if ( !IO.IsNull() && IO->hasEntry() ) { + QList views; + if ( onlyInActiveView ) + views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() ); + else + views = SUIT_Session::session()->activeApplication()->desktop()->windows(); + + foreach ( SUIT_ViewWindow* view, views ) { + if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) { + OCCViewer_Viewer* occViewer=(OCCViewer_Viewer*)view->getViewManager()->getViewModel(); + SOCC_Viewer* soccViewer = dynamic_cast(occViewer); + if (soccViewer) { + SOCC_Prs* occPrs = dynamic_cast( soccViewer->CreatePrs( IO->getEntry() ) ); + if ( occPrs && !occPrs->IsNull() ) { + AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes ); + if( !shapes.Extent() ) continue; + aisObject=shapes.First(); + delete occPrs; + } + } + } + if ( !aisObject.IsNull() ) break; + } // foreach } - testResult = false; - return res; + + return aisObject; } //======================================================================= -// function : ConvertIOinGEOMShape() +// function : ConvertIOinGEOMAISShape() // purpose : //======================================================================= -GEOM::GEOM_Shape_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) +Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape( const Handle(SALOME_InteractiveObject)& IO, bool onlyInActiveView ) { - GEOM::GEOM_Shape_var aShape; - testResult = false; - - /* case SObject */ - if(IO->hasEntry()) { - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if(!obj->_is_nil()) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - aShape = myGeom->GetIORFromString(anIOR->Value()); - if(!CORBA::is_nil(aShape)) - testResult = true; - return aShape._retn(); - } - } - } - /* case Graphical Object */ - if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) { - Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO); - Standard_CString ior = GIObject->getIOR(); - - aShape = myGeom->GetIORFromString(ior); - if(!CORBA::is_nil(aShape)) - testResult = true; - return aShape._retn(); - } - return aShape._retn(); + return Handle(GEOM_AISShape)::DownCast( GetAIS( IO, onlyInActiveView, true ) ); } //======================================================================= // function : ConvertListOfIOInListOfIOR() -// purpose : +// purpose : //======================================================================= -void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::GEOM_Gen::ListOfIOR& listIOR) +QStringList GEOMBase::ConvertListOfIOInListOfIOR( const SALOME_ListIO& IObjects ) { - int nbSel = aList.Extent(); - listIOR.length(nbSel); - int j=0; - SALOME_ListIteratorOfListIO It(aList); - for(int i=0; It.More(); It.Next(), i++) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - if(IObject->hasEntry()) { - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if(!obj->_is_nil() && obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - ORB_INIT &init = *SINGLETON_::Instance(); - CORBA::ORB_var& _orb = init.orb(); - CORBA::String_var theValue = anIOR->Value(); - CORBA::Object_var theObj = _orb->string_to_object(theValue); - if(theObj->_is_a("IDL:GEOM/GEOM_Shape:1.0")) { - listIOR[j] = strdup(theValue); - j++; - } - } - } - else if(IObject->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) { - Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IObject); - Standard_CString ior = GIObject->getIOR(); - listIOR[j] = strdup(ior); - j++; + QStringList iors; + SALOME_ListIteratorOfListIO it( IObjects ); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + for ( ; it.More(); it.Next() ) { + GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() ); + if ( !CORBA::is_nil( geomObj ) ) + iors.append( GetIORFromObject( geomObj ) ); } } - listIOR.length(j); + return iors; } -//================================================================================ -// function : SetDisplayedObjectList() +//======================================================================= +// function : ConvertIOinGEOMObject() // purpose : -//================================================================================ -// void GEOMBase::SetDisplayedObjectList() -// { -// if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) -// return; - -// OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); -// myGeomGUI->GetListDisplayedObject().Clear(); - -// Handle (AIS_InteractiveContext) aContext = v3d->getAISContext(); -// aContext->DisplayedObjects(myGeomGUI->GetListDisplayedObject()); -// } - - -//===================================================================================== -// function : DisplaySimulationShape() -// purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape -//===================================================================================== -void GEOMBase::DisplaySimulationShape(const TopoDS_Shape& S) +//======================================================================= +GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& IO ) { - if(S.IsNull()) - return; - - //NRI DEBUG : 14/02/2002 - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - try { - /* erase any previous */ - ic->Erase(mySimulationShape, Standard_True, Standard_False); - ic->ClearPrs(mySimulationShape); - mySimulationShape = new AIS_Shape(TopoDS_Shape()); - mySimulationShape->Set(S); - mySimulationShape->SetColor(Quantity_NOC_VIOLET); - ic->Deactivate(mySimulationShape); - ic->Display(mySimulationShape, Standard_False); - ic->UpdateCurrentViewer(); + GEOM::GEOM_Object_var object; + + if ( !IO.IsNull() && IO->hasEntry() ) { + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + _PTR(SObject) obj = studyDS->FindObjectID( IO->getEntry() ); + if ( GeometryGUI::IsInGeomComponent( obj )) { + CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj ); + object = GEOM::GEOM_Object::_narrow( corbaObj ); + } + } } - catch(Standard_Failure) { - MESSAGE("Exception catched in GEOMBase::DisplaySimulationShape "); - } - mySimulationShape->UnsetColor(); - return; + return object._retn(); } -//================================================================================== -// function : EraseSimulationShape() -// purpose : Clears the display of 'mySimulationShape' a pure graphical shape -//================================================================================== -void GEOMBase::EraseSimulationShape() +//======================================================================= +// function : ConvertListOfIOInListOfGO() +// purpose : +//======================================================================= +void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& IObjects, + GEOM::ListOfGO& geomObjects, + bool shapesOnly ) { - int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount(); - for(int i = 0; i < count; i++) { - if(QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - ic->Erase(mySimulationShape, Standard_True, Standard_False); - ic->ClearPrs(mySimulationShape); - ic->UpdateCurrentViewer(); - } + geomObjects.length( 0 ); + + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + + geomObjects.length( IObjects.Extent() ); + SALOME_ListIteratorOfListIO it( IObjects ); + + int i = 0; + for ( ; it.More(); it.Next() ) { + GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() ); + if ( !CORBA::is_nil( geomObj ) && ( !shapesOnly || IsShape( geomObj ) ) ) + geomObjects[ i++ ] = geomObj; + } + geomObjects.length( i ); } } - //================================================================================= // function : CreateArrowForLinearEdge() // purpose : Create a cone topology to be used to display an arrow in the middle // : of an edge showing its orientation. (For simulation and Viewer OCC only) //================================================================================= -bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone) +TopoDS_Shape GEOMBase::CreateArrowForLinearEdge( const TopoDS_Shape& shape ) { - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC || tds.ShapeType() != TopAbs_EDGE) - return false; - - OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort(); - Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView(); - Standard_Real Width, Height; - view3d->Size(Width, Height); - const Standard_Real aHeight = (Width + Height) / 50.0; - - try { - Standard_Real first, last; - Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last); - if(!curv->IsCN(1)) - return false; - - const Standard_Real param = (first+last) / 2.0; - gp_Pnt middleParamPoint; - gp_Vec V1; - curv->D1( param, middleParamPoint, V1); - if(V1.Magnitude() < Precision::Confusion()) - return false; - - /* Topology orientation not geom orientation */ - if(tds.Orientation() == TopAbs_REVERSED) - V1 *= -1.0; - - gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1)); - const Standard_Real radius1 = aHeight / 5.0; - if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) { - ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape(); - return true; + TopoDS_Shape ArrowCone; + + SUIT_ViewWindow* view = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); + if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() && shape.ShapeType() == TopAbs_EDGE ) { + Handle(V3d_View) view3d = ((OCCViewer_ViewWindow*)view)->getViewPort()->getView(); + Standard_Real Width, Height; + view3d->Size( Width, Height ); + const Standard_Real aHeight = (Width + Height) / 50.0; + + try { + Standard_Real first, last; + Handle(Geom_Curve) curv = BRep_Tool::Curve( TopoDS::Edge( shape ), first, last ); + if ( !curv.IsNull() && curv->IsCN(1) ) { + const Standard_Real param = ( first+last ) / 2.0; + gp_Pnt middleParamPoint; + gp_Vec V1; + curv->D1( param, middleParamPoint, V1 ); + if ( V1.Magnitude() > Precision::Confusion() ) { + /* Topology orientation not geom orientation */ + if ( shape.Orientation() == TopAbs_REVERSED ) + V1 *= -1.0; + + gp_Ax2 anAxis( middleParamPoint, gp_Dir( V1 ) ); + const Standard_Real radius1 = aHeight / 5.0; + if ( radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion() ) + ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape(); + } + } + } + catch ( Standard_Failure& ) { + // OCC failures are hard to catch in GUI. + // This is because of the position for #include that is very critical to find + // in SALOME environment : compilation error ! } } - catch(Standard_Failure) { - // OCC failures are hard to catch in GUI. - // This because of the position for #include that is very critic to find - // in SALOME environment : compilation error ! - } - return false; + + return ArrowCone; } @@ -1347,25 +539,24 @@ bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& A // function : VertexToPoint() // purpose : If S can be converted in a gp_Pnt returns true and the result is P //================================================================================= -bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P) +bool GEOMBase::VertexToPoint( const TopoDS_Shape& shape, gp_Pnt& point ) { - if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX) + if ( shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX ) return false; - P = BRep_Tool::Pnt(TopoDS::Vertex(S)); + point = BRep_Tool::Pnt( TopoDS::Vertex( shape ) ); return true; } //================================================================================= // function : GetBipointDxDyDz() -// purpose : +// purpose : //================================================================================= -void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz) +void GEOMBase::GetBipointDxDyDz( const gp_Pnt& point1, const gp_Pnt& point2, double& dx, double& dy, double& dz ) { - dx = P2.X() - P1.X(); - dy = P2.Y() - P1.Y(); - dz = P2.Z() - P1.Z(); - return; + dx = point2.X() - point1.X(); + dy = point2.Y() - point1.Y(); + dz = point2.Z() - point1.Z(); } @@ -1375,90 +566,71 @@ void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, do // : distance is sufficient, returns true else returns false. // : Resulting points are respectively P1 and P2 //================================================================================= -bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2) +bool GEOMBase::LinearEdgeExtremities( const TopoDS_Shape& shape, gp_Pnt& point1, gp_Pnt& point2 ) { - if(S.IsNull() || S.ShapeType() != TopAbs_EDGE) + if ( shape.IsNull() || shape.ShapeType() != TopAbs_EDGE ) return false; - BRepAdaptor_Curve curv(TopoDS::Edge(S)); - if(curv.GetType() != GeomAbs_Line) + + BRepAdaptor_Curve curv( TopoDS::Edge( shape ) ); + if ( curv.GetType() != GeomAbs_Line ) return false; + + gp_Pnt p1, p2; - curv.D0(curv.FirstParameter(), P1); - curv.D0(curv.LastParameter(), P2); + curv.D0( curv.FirstParameter(), p1 ); + curv.D0( curv.LastParameter(), p2 ); - if(P1.Distance(P2) <= Precision::Confusion()) + if ( p1.Distance( p2 ) <= Precision::Confusion() ) return false; + point1 = p1; + point2 = p2; return true; } -//======================================================================= -// function : Parameter() -// purpose : return a parameter (float) from a dialog box -// -// avalue1 : is a float or integer used as a default value displayed -// aTitle1 : is the title for aValue1 -// aTitle : is the main title -// bottom : maximum value to be entered -// top : minimum value to be entered -// decimals : number of decimals -//======================================================================= -double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals) -{ - GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, QAD_Application::getDesktop(), aTitle, TRUE, 0, bottom, top, decimals); - int r = Dialog->exec(); - float X = 0.0; - if(r == QDialog::Accepted) { - res = Standard_True; - X = Dialog->getValue(); - } - else - res = Standard_False; - delete Dialog; - return X; -} - - //======================================================================= // function : SelectionByNameInDialogs() // purpose : Called when user has entered a name of object in a LineEdit. -// : The selection is changed. Dialog box will receive the +// : The selection is changed. Dialog box will receive the // : corresponding signal to manage this event. //======================================================================= -bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, SALOME_Selection* Sel) +bool GEOMBase::SelectionByNameInDialogs( QWidget* widget, const QString& objectUserName, const SALOME_ListIO& /*IObjects*/ ) { /* Find SObject with name in component GEOM */ - SALOMEDS::Study_var ST = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject; - listSO = ST->FindObjectByName(objectUserName, "GEOM"); - - if(listSO->length() < 1) { - const QString caption = tr("GEOM_WRN_WARNING"); - const QString text = tr("GEOM_NAME_INCORRECT"); - const QString button0 = tr("GEOM_BUT_OK"); - QMessageBox::warning(aWidget, caption, text, button0); + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( !study ) return false; + _PTR(Study) studyDS = study->studyDS(); + + std::vector<_PTR(SObject)> listSO = studyDS->FindObjectByName( objectUserName.toStdString(), "GEOM" ); + + if ( listSO.size() < 1 ) { + SUIT_MessageBox::critical( widget, + QObject::tr( "GEOM_WRN_WARNING" ), + QObject::tr( "GEOM_NAME_INCORRECT" ), + QObject::tr( "GEOM_BUT_OK" ) ); return false; } + /* More than one object with same name */ - if(listSO->length() > 1) { - const QString caption = tr("GEOM_WRN_WARNING"); - const QString text = tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE"); - const QString button0 = tr("GEOM_BUT_OK") ; - QMessageBox::warning(aWidget, caption, text, button0) ; + if ( listSO.size() > 1 ) { + SUIT_MessageBox::critical( widget, + QObject::tr("GEOM_WRN_WARNING"), + QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE"), + QObject::tr("GEOM_BUT_OK") ); return false; } - SALOMEDS::SObject_var theObj = listSO[0]; /* Create a SALOME_InteractiveObject with a SALOME::SObject */ - Standard_CString anEntry = theObj->GetID(); - Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(anEntry, "GEOM", strdup(objectUserName)); + Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject( listSO[0]->GetID().c_str(), + "GEOM", + objectUserName.toUtf8().constData() ); /* Add as a selected object */ /* Clear any previous selection : */ - /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */ - Sel->ClearIObjects(); - Sel->AddIObject(SI); + /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */ + // Sel->ClearIObjects(); //mzn + // Sel->AddIObject(SI); //mzn return true; } @@ -1467,22 +639,268 @@ bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectU // function : DefineDlgPosition() // purpose : Define x and y the default position for a dialog box //======================================================================= -bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y) +void GEOMBase::DefineDlgPosition( QWidget* dlg, int& x, int& y ) { /* Here the position is on the bottom right corner - 10 */ - QAD_Desktop* PP = QAD_Application::getDesktop(); - x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10); - y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10); - return true; + SUIT_Desktop* d = SUIT_Session::session()->activeApplication()->desktop(); + x = abs( d->x() + d->size().width() - dlg->size().width() - 10 ); + y = abs( d->y() + d->size().height() - dlg->size().height() - 10 ); } -//===================================================================================== -// EXPORTED METHODS -//===================================================================================== -extern "C" +//======================================================================= +// function : GetDefaultName() +// purpose : Generates default names +//======================================================================= +QString GEOMBase::GetDefaultName( const QString& operation, bool extractPrefix ) { - bool CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, - const QString & theParent, const QString & theObject) - {return GEOMBase::CustomPopup(parent, popup, theContext, theParent, theObject);} + QString aName = ""; + + // collect all object names of GEOM component + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study ) { + _PTR(Study) studyDS = study->studyDS(); + + std::set names; + _PTR(SComponent) component( studyDS->FindComponent( "GEOM" ) ); + if ( component ) { + _PTR(ChildIterator) it( studyDS->NewChildIterator( component ) ); + for ( it->InitEx( true ); it->More(); it->Next() ) { + names.insert( it->Value()->GetName() ); + } + } + + // build a unique name + int aNumber = 0; + bool isUnique = false; + QString prefix = operation; + + if ( extractPrefix ) { + QStringList parts = prefix.split( "_", QString::KeepEmptyParts ); + if ( parts.count() > 1 ) { + bool ok; + aNumber = parts.last().toLong( &ok ); + if ( ok ) { + parts.removeLast(); + prefix = parts.join( "_" ); + aNumber--; + } + } + } + + while ( !isUnique ) { + aName = prefix + "_" + QString::number( ++aNumber ); + isUnique = ( names.count( aName.toStdString()) == 0 ); + } + } + return aName; +} + + +//======================================================================= +// function : ShowErrorMessage() +// purpose : Shows message box with error code and comment +//======================================================================= +void GEOMBase::ShowErrorMessage( const QString& errorCode, const QString& comment ) +{ + QStringList text; + text << QObject::tr( "GEOM_PRP_ABORT" ); + if ( !errorCode.isEmpty() ) + text << QObject::tr( errorCode.toLatin1().constData() ); + if ( !comment.isEmpty() ) + text << QObject::tr( comment.toUtf8().constData() ); + + SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), + QObject::tr( "GEOM_ERROR" ), + text.join( "\n" ), + QObject::tr( "GEOM_BUT_OK" ) ); +} + + +//======================================================================= +// function : GetObjectFromIOR() +// purpose : returns a GEOM_Object by given IOR (string) +//======================================================================= +GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const QString& IOR ) +{ + return GeometryGUI::GetObjectFromIOR (IOR); +} + +//======================================================================= +// function : GetIORFromObject() +// purpose : returns IOR of a given GEOM_Object +//======================================================================= +QString GEOMBase::GetIORFromObject( GEOM::GEOM_Object_ptr object ) +{ + return GeometryGUI::GetIORFromObject (object); +} + +//======================================================================= +// function : GetShape() +// purpose : returns a TopoDS_Shape stored in GEOM_Object +//======================================================================= +bool GEOMBase::GetShape( GEOM::GEOM_Object_ptr object, TopoDS_Shape& shape, const TopAbs_ShapeEnum type ) +{ + shape = TopoDS_Shape(); + if ( !CORBA::is_nil( object ) ) { + TopAbs_ShapeEnum stype = (TopAbs_ShapeEnum)( object->GetShapeType() ); + if ( type == TopAbs_SHAPE || type == stype ) + { + GEOM::GEOM_Gen_var gen = object->GetGen(); + shape = GEOM_Client::get_client().GetShape( gen, object ); + } + } + return !shape.IsNull(); +} + +//======================================================================= +// function : GetName() +// purpose : Get name of object +//======================================================================= +QString GEOMBase::GetName( GEOM::GEOM_Object_ptr object ) +{ + QString name; + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + + if ( !CORBA::is_nil( object ) ) { + // 1. search if object is already published in the study + CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( object ); + if ( study && strcmp( IOR.in(), "" ) != 0 ) { + _PTR(SObject) aSObj( study->studyDS()->FindObjectIOR( std::string( IOR.in() ) ) ); + _PTR(GenericAttribute) anAttr; + if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) { + _PTR(AttributeName) aNameAttr( anAttr ); + name = aNameAttr->Value().c_str(); + } + } + + // 2. if object is not found in the study, try default name + if ( name.isEmpty() ) { + if ( object->IsMainShape() ) { + name = GetDefaultName( "geomObj" ); + } + else { + GEOM::GEOM_Object_var mainShape = object->GetMainShape(); + if ( !CORBA::is_nil( mainShape ) ) { + GEOM::ListOfLong_var indices = object->GetSubShapeIndices(); + if ( indices->length() > 0 ) { + TopAbs_ShapeEnum type = (TopAbs_ShapeEnum)( object->GetShapeType() ); + name = QString( "%1:%2_%3" ).arg( GetName( mainShape.in() ) ) + .arg( TypeName( type ) ).arg( indices[0] ); + } + } + } + } + } + + return name; +} + +//======================================================================= +// function : IsShape() +// purpose : Return TRUE if object is valid and has shape +//======================================================================= +bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr object ) +{ + return !object->_is_nil() && object->IsShape(); +} + +//======================================================================= +// function : TypeName() +// purpose : Get string representation for the shape type +//======================================================================= +QString GEOMBase::TypeName( TopAbs_ShapeEnum type, bool capitalize ) +{ + QString name = "shape"; + switch( type ) { + case TopAbs_COMPSOLID: + name = "compsolid"; break; + case TopAbs_COMPOUND: + name = "compound"; break; + case TopAbs_SOLID: + name = "solid"; break; + case TopAbs_SHELL: + name = "shell"; break; + case TopAbs_FACE: + name = "face"; break; + case TopAbs_WIRE: + name = "wire"; break; + case TopAbs_EDGE: + name = "edge"; break; + case TopAbs_VERTEX: + name = "vertex"; break; + default: + break; + } + if ( capitalize && !name.isEmpty() ) + name = name.left(1).toUpper() + name.mid(1); + return name; +} + +//================================================================ +// Function : GetEntry +// Purpose : Get study entry for the given object (if it is published) +//================================================================ +QString GEOMBase::GetEntry( GEOM::GEOM_Object_ptr object ) +{ + QString entry; + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study && !CORBA::is_nil( object ) ) { + QString objIOR = GetIORFromObject( object ); + if ( !objIOR.isEmpty() ) { + _PTR(SObject) SO( study->studyDS()->FindObjectIOR( objIOR.toLatin1().constData() ) ); + if ( SO ) + entry = SO->GetID().c_str(); + } + } + return entry; +} + +//================================================================ +// Function : PublishSubObject +// Purpose : Publish sub-shape under the main object +//================================================================ +void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object, const QString& name ) +{ + SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( study && !CORBA::is_nil( object ) ) { + _PTR(Study) studyDS = study->studyDS(); + QString entry = GetEntry( object ); + GEOM::GEOM_Object_var father = object->GetMainShape(); + QString fatherEntry = GetEntry( father ); + if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) { + QString aName = !name.isEmpty() ? name : GetName( object ); + GeometryGUI::GetGeomGen()->AddInStudy( object, aName.toUtf8().data(), father.in() ); + } + } +} + +//================================================================ +// Function : synchronize +// Purpose : +//================================================================ +void GEOMBase::Synchronize( QList& left, QList& right ) +{ + // 1. remove items from the "left" list that are not in the "right" list + QMutableListIterator it1( left ); + while ( it1.hasNext() ) { + GEOM::GeomObjPtr o1 = it1.next(); + bool found = false; + QMutableListIterator it2( right ); + while ( it2.hasNext() && !found ) + found = o1 == it2.next(); + if ( !found ) + it1.remove(); + } + // 2. add items from the "right" list that are not in the "left" list (to keep selection order) + it1 = right; + while ( it1.hasNext() ) { + GEOM::GeomObjPtr o1 = it1.next(); + bool found = false; + QMutableListIterator it2( left ); + while ( it2.hasNext() && !found ) + found = o1 == it2.next(); + if ( !found ) + left << o1; + } }