-// // QT Includes
-#include <qmessagebox.h>
-
-#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()) {
- if (strcmp(obj->GetFatherComponent()->GetName(), "GEOM")) continue;
- 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()) {
- if (strcmp(obj->GetFatherComponent()->GetName(), "GEOM")) continue;
- 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");
- aStudyBuilder->DefineComponentInstance(father, myGeom);
- QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
- if(aLocked)
- aStudy->GetProperties()->SetLocked(true);
- op->finish();
- }
-
- 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->myNbGeom++) + TCollection_AsciiString("\0");
- }
- else
- nameG += TCollection_AsciiString(aShape->NameType()) + TCollection_AsciiString("_") + TCollection_AsciiString(myGeomGUI->myNbGeom++) + 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->SetInfiniteState(shape.Infinite());
- 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);