1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOMBase.cxx
25 // Author : Damien COQUERET
33 # include "Utils_ORB_INIT.hxx"
34 # include "Utils_SINGLETON.hxx"
36 #include "QAD_RightFrame.h"
37 #include "QAD_MessageBox.h"
38 #include "QAD_Resource.h"
40 #include "GEOM_AssemblyBuilder.h"
41 #include "VTKViewer_ViewFrame.h"
42 #include "OCCViewer_ViewPort3d.h"
43 #include "OCCViewer_Viewer3d.h"
45 #include "SALOME_ListIteratorOfListIO.hxx"
46 #include "SALOMEGUI_ImportOperation.h"
47 #include "SALOMEGUI_NameDlg.h"
49 // // Open CASCADE Includes
50 #include <BRep_Tool.hxx>
51 #include <BRepAdaptor_Curve.hxx>
52 #include <BRepAdaptor_Surface.hxx>
53 #include <BRepPrimAPI_MakeCone.hxx>
55 #include <Geom_Circle.hxx>
56 #include <AIS_ListIteratorOfListOfInteractive.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopoDS_Iterator.hxx>
62 #include <TopoDS_Compound.hxx>
63 #include <TopTools_MapOfShape.hxx>
64 #include <TopTools_ListIteratorOfListOfShape.hxx>
66 #include <Precision.hxx>
69 #include <qmessagebox.h>
71 #include "GEOMBase_aParameterDlg.h"
73 //=================================================================================
75 // purpose : Set Font to a text.
76 //=================================================================================
77 class CustomItem : public QCustomMenuItem
80 CustomItem(const QString& s, const QFont& f)
81 :string(s), font(f){};
84 void paint(QPainter* p, const QColorGroup& /*cg*/, bool /*act*/,
85 bool /*enabled*/, int x, int y, int w, int h)
88 p->drawText(x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
93 return QFontMetrics(font).size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
103 //=======================================================================
104 // function : GEOMBase()
105 // purpose : Constructor
106 //=======================================================================
107 GEOMBase::GEOMBase() :
110 myGeomGUI = GEOMContext::GetGeomGUI();
111 myGeom = myGeomGUI->myComponentGeom;
114 QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed");
115 QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen");
116 QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue");
117 if(!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
118 myShadingColor = Quantity_Color(SCr.toInt()/255., SCg.toInt()/255., SCb.toInt()/255., Quantity_TOC_RGB);
120 myShadingColor = Quantity_Color(Quantity_NOC_GOLDENROD);
122 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
123 if(!AddInStudy.isEmpty())
124 mySettings_AddInStudy = AddInStudy.toInt();
126 mySettings_AddInStudy = 1;
130 //=======================================================================
131 // function : ~GEOMBase()
132 // purpose : Destructor
133 //=======================================================================
134 GEOMBase::~GEOMBase()
139 //=================================================================================
140 // function : CustomPopup()
141 // purpose : [static]
142 //=================================================================================
143 bool GEOMBase::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
144 const QString& theParent, const QString& theObject)
146 GEOMBase* myGeomBase = new GEOMBase();
147 QAD_Study* ActiveStudy = parent->getActiveStudy();
149 /* Deactivate any non modal dialog box to get the neutral point */
150 myGeomBase->myGeomGUI->EmitSignalDeactivateDialog();
152 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
153 int nbSel = Sel->IObjectCount();
158 if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
159 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
160 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
161 if(theParent.compare("Viewer") == 0) {
162 if(theObject.compare("Component") == 0) {
163 popup->removeItem(QAD_DisplayOnly_Popup_ID);
167 QFont f = QApplication::font();
170 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
171 popup->removeItem(QAD_TopLabel_Popup_ID);
172 popup->insertItem(new CustomItem (QString(IObject->getName()), f), QAD_TopLabel_Popup_ID, 0);
173 if(IObject->hasEntry())
174 popup->setItemEnabled(804, false); //Add in Study Menu
176 popup->setItemEnabled(804, true); //Add in Study Menu
178 if(IObject->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
179 Standard_Boolean found;
180 Handle(GEOM_AISShape) Result = myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true);
183 if(Result->DisplayMode() == 1)
184 popup->changeItem(8031, tr("GEOM_MEN_WIREFRAME")); //Shading/Wireframe Menu
186 popup->changeItem(8031, tr("GEOM_MEN_SHADING")); //Shading/Wireframe Menu
190 if(!(v3d->isInViewer(IObject) && v3d->isVisible(IObject)))
191 popup->removeItem(QAD_Erase_Popup_ID);
193 popup->removeItem(QAD_Display_Popup_ID);
196 popup->removeItem(QAD_DisplayOnly_Popup_ID);
197 popup->removeItem(QAD_TopLabel_Popup_ID);
198 popup->insertItem(new CustomItem (tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f), QAD_TopLabel_Popup_ID, 0);
199 popup->setItemEnabled(804, false); //Add in Study Menu
204 else if(theParent.compare("ObjectBrowser") == 0) {
205 popup->removeItem(QAD_TopLabel_Popup_ID);
206 int id = popup->idAt(0); // separator
208 popup->removeItem(id);
210 // checking for GEOM label in the selected list
211 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
212 Handle(SALOME_InteractiveObject) anIObject;
214 bool useSubItems = false;
215 bool needOpen = false;
216 bool needDisplay = false;
217 bool needErase = false;
218 SALOMEDS::GenericAttribute_var aTmpAttr;
219 for(;It.More();It.Next()) {
220 anIObject = It.Value();
221 if(!anIObject->hasEntry())
224 if(v3d->isInViewer(anIObject) && v3d->isVisible(anIObject))
228 SALOMEDS::SObject_var obj = ActiveStudy->getStudyDocument()->FindObjectID(anIObject->getEntry());
229 if(!obj->_is_nil()) {
230 if (strcmp(obj->GetFatherComponent()->GetName(), "GEOM")) continue;
231 GEOM::GEOM_Shape_var aShape;
232 if(obj->FindAttribute(aTmpAttr, "AttributeIOR")) {
233 char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
234 if(str && strlen(str))
235 aShape = myGeomBase->myGeom->GetIORFromString(str);
237 else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
240 if(aShape->_is_nil()) {
241 SALOMEDS::ChildIterator_var anIter = ActiveStudy->getStudyDocument()->NewChildIterator(obj);
242 while(anIter->More()) {
243 SALOMEDS::SObject_var subobj = anIter->Value();
244 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
249 else if(subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) {
258 // remove useless popup items
260 popup->removeItem(901); // rename
262 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
265 int index = popup->indexOf(9024); // open
266 popup->removeItem(9024);
267 popup->removeItemAt(index); // separator under Open
270 popup->removeItem(QAD_Display_Popup_ID);
272 popup->removeItem(QAD_Erase_Popup_ID);
274 if(!needDisplay && !needErase) {
275 int id = popup->idAt(popup->count()-1); // last item
276 popup->removeItem(id); // separator
280 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
281 popup->removeItem(QAD_Display_Popup_ID);
282 popup->removeItem(QAD_Erase_Popup_ID);
284 int id = popup->idAt(popup->count()-1); // last item
285 popup->removeItem(id); // separator
291 else if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
292 // MESSAGE ( " CUSTOM POPUP VIEWER VTK ")
293 if((theParent.compare("Viewer") == 0)) {
294 popup->setItemEnabled(8034, false); //Isos Menu
295 if(theObject.compare("Component") == 0) {
296 popup->removeItem(QAD_DisplayOnly_Popup_ID);
300 //int id = popup->idAt(0);
301 QFont f = QApplication::font();
305 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
306 popup->removeItem(QAD_TopLabel_Popup_ID);
307 popup->insertItem(new CustomItem (QString(IObject->getName()), f), QAD_TopLabel_Popup_ID, 0);
308 if(IObject->hasEntry()) {
309 popup->setItemEnabled(804, false); //Add in Study Menu
310 SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
311 SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
312 SALOMEDS::GenericAttribute_var anAttr;
313 SALOMEDS::AttributeIOR_var anIOR;
315 if(SO->FindAttribute(anAttr, "AttributeIOR")) {
316 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
317 Standard_Boolean found;
318 GEOM_Actor* Result = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), found, true);
320 if(Result->getDisplayMode() == 1)
321 popup->changeItem(8031, tr("GEOM_MEN_WIREFRAME")); //Shading/Wireframe Menu
323 popup->changeItem(8031, tr("GEOM_MEN_SHADING")); //Shading/Wireframe Menu
325 if(!Result->GetVisibility())
326 popup->removeItem(QAD_Erase_Popup_ID);
328 popup->removeItem(QAD_Display_Popup_ID);
331 popup->removeItem(QAD_Erase_Popup_ID);
336 popup->setItemEnabled(804, true); //Add in Study Menu
339 popup->removeItem(QAD_DisplayOnly_Popup_ID);
340 popup->removeItem(QAD_TopLabel_Popup_ID);
341 popup->insertItem( new CustomItem (tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f), QAD_TopLabel_Popup_ID, 0);
342 popup->setItemEnabled(804, false); //Add in Study Menu
346 else if(theParent.compare("ObjectBrowser") == 0) {
347 popup->removeItem(QAD_TopLabel_Popup_ID);
348 int id = popup->idAt(0); // separator
350 popup->removeItem(id);
352 // checking for GEOM label in the selected list
353 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
354 Handle(SALOME_InteractiveObject) anIObject;
356 bool useSubItems = false;
357 bool needOpen = false;
358 bool needDisplay = false;
359 bool needErase = false;
360 SALOMEDS::GenericAttribute_var aTmpAttr;
361 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
362 for(;It.More();It.Next()) {
363 anIObject = It.Value();
364 if(!anIObject->hasEntry())
367 if(myRenderInter->isInViewer(anIObject) && myRenderInter->isVisible(anIObject))
372 SALOMEDS::SObject_var obj = ActiveStudy->getStudyDocument()->FindObjectID(anIObject->getEntry());
373 if(!obj->_is_nil()) {
374 if (strcmp(obj->GetFatherComponent()->GetName(), "GEOM")) continue;
375 GEOM::GEOM_Shape_var aShape;
376 if(obj->FindAttribute(aTmpAttr, "AttributeIOR")) {
377 char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
378 if(str && strlen(str))
379 aShape = myGeomBase->myGeom->GetIORFromString(str);
381 else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
384 if(aShape->_is_nil()) {
385 SALOMEDS::ChildIterator_var anIter = ActiveStudy->getStudyDocument()->NewChildIterator(obj);
386 while(anIter->More()) {
387 SALOMEDS::SObject_var subobj = anIter->Value();
388 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
393 else if(subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) {
402 // remove useless popup items
404 popup->removeItem(901); // rename
406 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
409 int index = popup->indexOf(9024); // open
410 popup->removeItem(9024);
411 popup->removeItemAt(index); // separator under Open
414 popup->removeItem(QAD_Display_Popup_ID);
416 popup->removeItem(QAD_Erase_Popup_ID);
417 if(!needDisplay && !needErase) {
418 int id = popup->idAt(popup->count()-1); // last item
419 popup->removeItem(id); // separator
423 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
424 popup->removeItem(QAD_Display_Popup_ID);
425 popup->removeItem(QAD_Erase_Popup_ID);
427 int id = popup->idAt(popup->count()-1); // last item
428 popup->removeItem(id); // separator
434 else { // other viewer types not supported.
436 int id = popup->idAt(0);
437 if(id <= QAD_TopLabel_Popup_ID && id != -1)
438 popup->removeItemAt(0);
442 popup->removeItem(QAD_DisplayOnly_Popup_ID);
443 popup->removeItem(QAD_Display_Popup_ID);
444 popup->removeItem(QAD_Erase_Popup_ID);
445 int id = popup->idAt(popup->count() - 1); // last item
446 if(id < 0 && id != -1)
447 popup->removeItem(id); // separator
454 //=====================================================================================
455 // function : Display()
456 // purpose : Displays a CORBA shape
457 //=====================================================================================
458 bool GEOMBase::Display(GEOM::GEOM_Shape_ptr aShape, Standard_CString name)
460 // MESSAGE ( "GEOMBase::Display init ")
461 Handle(GEOM_InteractiveObject) IO;
462 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
463 Sel->ClearIObjects();
465 if(aShape->_is_nil()) {
466 QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_PRP_ABORT"), tr("GEOM_BUT_OK"));
470 TopoDS_Shape shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
474 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
475 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
476 SALOMEDS::GenericAttribute_var anAttr;
477 SALOMEDS::AttributeName_var aName;
478 SALOMEDS::AttributePixMap_var aPixmap;
480 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
482 if(father->_is_nil()) {
483 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
485 aLocked = aStudy->GetProperties()->IsLocked();
487 aStudy->GetProperties()->SetLocked(false);
488 father = aStudyBuilder->NewComponent("GEOM");
489 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
490 aName = SALOMEDS::AttributeName::_narrow(anAttr);
491 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName("GEOM"));
492 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
493 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
494 aPixmap->SetPixMap("ICON_OBJBROWSER_Geometry");
495 aStudyBuilder->DefineComponentInstance(father, myGeom);
496 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
498 aStudy->GetProperties()->SetLocked(true);
502 father->ComponentIOR(myGeomGUI->GetFatherior());
504 TCollection_AsciiString nameG("");
505 Standard_CString Type;
506 if(TCollection_AsciiString(name).IsEqual(Standard_CString(""))) {
507 if(TCollection_AsciiString(aShape->NameType()).IsEqual(Standard_CString(""))) {
508 Standard_CString type;
509 GetShapeTypeString(shape,type);
510 aShape->NameType(type);
511 nameG += TCollection_AsciiString(type) + TCollection_AsciiString("_") + TCollection_AsciiString(myGeomGUI->myNbGeom++) + TCollection_AsciiString("\0");
514 nameG += TCollection_AsciiString(aShape->NameType()) + TCollection_AsciiString("_") + TCollection_AsciiString(myGeomGUI->myNbGeom++) + TCollection_AsciiString("\0");
517 nameG = TCollection_AsciiString(name);
520 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
521 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
523 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
524 int themode = myRenderInter->GetDisplayMode();
526 vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(shape, 0, themode, Standard_True);
527 theActors->InitTraversal();
528 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
530 IO = new GEOM_InteractiveObject(aShape->Name(), myGeomGUI->GetFatherior(), "GEOM");
531 while(!(anActor==NULL)) {
532 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
534 GActor->setName(nameG.ToCString());
536 theRenderer->AddActor(GActor);
537 anActor = (vtkActor*)theActors->GetNextActor();
541 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
542 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
543 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
544 Handle(GEOM_AISShape) theResult = new GEOM_AISShape(shape, nameG.ToCString());
545 theResult->SetInfiniteState(shape.Infinite());
546 theResult->SetShadingColor(myShadingColor);
547 IO = new GEOM_InteractiveObject(aShape->Name(), myGeomGUI->GetFatherior(), "GEOM");
548 theResult->setIO(IO);
549 theResult->setName(nameG.ToCString());
551 /* Precaution : close any local context to permit the display */
552 if(ic->HasOpenedContext())
553 ic->CloseAllContexts();
555 ic->Display(theResult);
558 // DCQ Sel->AddIObject(IO, false);
559 QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
560 if(mySettings_AddInStudy)
561 AddInStudy(false, IO);
567 //=====================================================================================
568 // function : AddInStudy()
569 // purpose : anIOShape or a selected shape
570 //=====================================================================================
571 bool GEOMBase::AddInStudy(bool selection, const Handle(SALOME_InteractiveObject)& anIO)
573 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
574 if (!(!mySettings_AddInStudy || selection)) {
575 Sel->ClearIObjects();
578 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
579 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
580 SALOMEDS::GenericAttribute_var anAttr;
581 SALOMEDS::AttributeName_var aName;
582 SALOMEDS::AttributePixMap_var aPixmap;
583 SALOMEDS::AttributeIOR_var anIOR;
584 SALOMEDS::AttributeSelectable_var aSelAttr;
586 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
588 if(father->_is_nil()) {
589 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
591 aLocked = aStudy->GetProperties()->IsLocked();
593 aStudy->GetProperties()->SetLocked(false);
594 father = aStudyBuilder->NewComponent("GEOM");
595 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
596 aName = SALOMEDS::AttributeName::_narrow(anAttr);
597 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName("GEOM"));
598 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
599 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
600 aPixmap->SetPixMap("ICON_OBJBROWSER_Geometry");
601 aStudyBuilder->DefineComponentInstance(father, myGeom);
603 aStudy->GetProperties()->SetLocked(true);
607 father->ComponentIOR(myGeomGUI->GetFatherior());
609 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
611 Handle(GEOM_AISShape) GAISShape;
613 Handle(GEOM_InteractiveObject) GIO;
617 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
618 vtkRenderer *Renderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
620 vtkActorCollection* theActors = Renderer->GetActors();
621 theActors->InitTraversal();
622 vtkActor *ac = theActors->GetNextActor();
624 if(ac->IsA("GEOM_Actor")) {
625 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
626 if(anActor->hasIO()) {
627 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
628 if(IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
629 GIO = Handle(GEOM_InteractiveObject)::DownCast(IO);
630 if(anIO->isSame(GIO)) {
638 ac = theActors->GetNextActor();
645 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
646 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
647 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
649 AIS_ListOfInteractive List;
650 ic->DisplayedObjects(List);
651 AIS_ListIteratorOfListOfInteractive ite(List);
653 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
654 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
656 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
657 if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
658 GIO = Handle(GEOM_InteractiveObject)::DownCast(IO);
659 if(anIO->isSame(GIO)) {
674 if(!mySettings_AddInStudy || selection) {
675 QString Name = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), anIO->getName());
676 if(!Name.isEmpty()) {
678 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
679 GActor->setName(strdup(Name.latin1()));
681 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
682 GAISShape->setName(strdup(Name.latin1()));
689 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
692 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
694 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(GIO->getIOR());
696 /* For the shape inserted into the study we set its field 'studyshapeid' */
697 /* so the shape will contain its corresponding entry in the study Ocaf doc. */
698 aShape->StudyShapeId(newObj->GetID());
700 GIO->setEntry(newObj->GetID());
702 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
703 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
704 anIOR->SetValue(aShape->Name());
706 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
707 aName = SALOMEDS::AttributeName::_narrow(anAttr);
709 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
710 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
711 if(aShape->ShapeType() == GEOM::COMPOUND)
712 aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
713 else if(aShape->ShapeType() == GEOM::COMPSOLID)
714 aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
715 else if(aShape->ShapeType() == GEOM::SOLID)
716 aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
717 else if(aShape->ShapeType() == GEOM::SHELL)
718 aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
719 else if(aShape->ShapeType() == GEOM::FACE)
720 aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
721 else if(aShape->ShapeType() == GEOM::WIRE)
722 aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
723 else if(aShape->ShapeType() == GEOM::EDGE)
724 aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
725 else if(aShape->ShapeType() == GEOM::VERTEX)
726 aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
729 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
731 aName->SetValue(GActor->getName());
734 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
735 GAISShape->setIO(GIO);
736 aName->SetValue(GAISShape->getName());
739 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
740 aStudyBuilder->Addreference(newObj1,newObj);
742 GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
743 listIOR = myGeom->GetReferencedObjects(aShape);
745 if(listIOR->length()>0) {
746 SALOMEDS::SObject_var Arguments = aStudyBuilder->NewObject(newObj);
747 anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeName");
748 aName = SALOMEDS::AttributeName::_narrow(anAttr);
749 aName->SetValue(tr("GEOM_ARGUMENTS"));
750 anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeSelectable");
751 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
752 aSelAttr->SetSelectable(false);
754 bool ObjectReferenced = false;
755 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
756 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(listIOR[ind]);
758 if(!theObj->_is_nil()) {
759 SALOMEDS::SObject_var RefObject = aStudyBuilder->NewObject(Arguments);
760 aStudyBuilder->Addreference(RefObject, theObj);
761 ObjectReferenced = true;
765 if(!ObjectReferenced)
766 aStudyBuilder->RemoveObject(Arguments);
770 if(!mySettings_AddInStudy || selection)
771 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
773 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(false);
774 // DCQ Sel->AddIObject(GIO);
780 //=====================================================================================
781 // function : GetShapeFromIOR()
782 // purpose : exist also as static method !
783 //=====================================================================================
784 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
787 if(IOR.stripWhiteSpace().isEmpty())
789 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
790 CORBA::ORB_var& _orb = init.orb() ;
791 CORBA::Object_var obj = _orb->string_to_object((char*)(IOR.latin1()));
792 if(CORBA::is_nil(obj))
794 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(IOR);
795 if(!aShape->_is_nil())
796 result = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
801 //=====================================================================================
802 // function : GetIndex()
803 // purpose : Get the index of a sub shape in a main shape : index start at 1
804 //=====================================================================================
805 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
807 if(shape.IsNull() || subshape.IsNull())
811 if(subshape.ShapeType() == TopAbs_COMPOUND) {
813 TopTools_ListOfShape CL;
815 TopTools_ListIteratorOfListOfShape itC;
816 for(itC.Initialize(CL); itC.More(); itC.Next()) {
817 for(it.Initialize(itC.Value()); it.More(); it.Next()) {
818 if(it.Value().ShapeType() == TopAbs_COMPOUND) {
819 if(it.Value().IsSame(subshape))
823 CL.Append(it.Value());
829 TopExp_Explorer Exp(shape, subshape.ShapeType());
830 TopTools_MapOfShape M;
832 if(M.Add(Exp.Current())) {
833 if(Exp.Current().IsSame(subshape))
844 //=======================================================================
845 // function : GetTopoFromSelection()
846 // purpose : Define tds from a single selection and retuen true
847 //=======================================================================
848 bool GEOMBase::GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds)
850 if(Sel->IObjectCount() != 1)
853 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
856 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
857 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
858 SALOMEDS::GenericAttribute_var anAttr;
859 SALOMEDS::AttributeIOR_var anIOR;
860 if(!obj->_is_nil()) {
861 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
862 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
863 tds = this->GetShapeFromIOR(anIOR->Value());
872 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
873 Standard_CString ior = "";
874 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
875 ior = GIObject->getIOR();
876 tds = this->GetShapeFromIOR(ior);
887 //=======================================================================
888 // function : GetNameOfSelectedIObjects()
889 // purpose : Define the name geom++ or other name of mono or multi sel.
890 //=======================================================================
891 int GEOMBase::GetNameOfSelectedIObjects(SALOME_Selection* Sel, QString& aName)
893 int nbSel = Sel->IObjectCount();
895 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
896 aName = IObject->getName();
899 aName = tr("%1_objects").arg(nbSel);
905 //=================================================================================
906 // function : GetShapeTypeString()
907 // purpose : for a single shape
908 //=================================================================================
909 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
911 if(aShape.IsNull()) {
912 aTypeString = "aNullShape";
915 switch(aShape.ShapeType())
917 case TopAbs_COMPOUND:
919 aTypeString = strdup(tr("GEOM_COMPOUND"));
922 case TopAbs_COMPSOLID:
924 aTypeString = strdup(tr("GEOM_COMPOUNDSOLID")) ;
929 aTypeString = strdup(tr("GEOM_SOLID")) ;
934 aTypeString = strdup(tr("GEOM_SHELL")) ;
939 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
940 if(surf.GetType() == GeomAbs_Plane) {
941 aTypeString = strdup(tr("GEOM_PLANE"));
944 else if(surf.GetType() == GeomAbs_Cylinder) {
945 aTypeString = strdup(tr("GEOM_SURFCYLINDER"));
948 else if(surf.GetType() == GeomAbs_Sphere) {
949 aTypeString = strdup(tr("GEOM_SURFSPHERE"));
952 else if(surf.GetType() == GeomAbs_Torus) {
953 aTypeString = strdup(tr("GEOM_SURFTORUS"));
956 else if(surf.GetType() == GeomAbs_Cone) {
957 aTypeString = strdup(tr("GEOM_SURFCONE"));
961 aTypeString = strdup(tr("GEOM_FACE"));
967 aTypeString = strdup(tr("GEOM_WIRE"));
972 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
973 if(curv.GetType() == GeomAbs_Line) {
974 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
975 aTypeString = strdup(tr("GEOM_LINE"));
977 aTypeString = strdup(tr("GEOM_EDGE"));
980 else if(curv.GetType() == GeomAbs_Circle) {
982 aTypeString = strdup(tr("GEOM_CIRCLE"));
984 aTypeString = strdup(tr("GEOM_ARC"));
988 aTypeString = strdup(tr("GEOM_EDGE"));
994 aTypeString = strdup(tr("GEOM_VERTEX"));
999 aTypeString = strdup(tr("GEOM_SHAPE"));
1007 //=======================================================================
1008 // function : ConvertIORinGEOMAISShape()
1010 //=======================================================================
1011 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
1013 Handle(GEOM_AISShape) resultShape;
1015 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1016 for(int i = 0; i < nbSf; i++) {
1017 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1018 if(sf->getTypeView() == VIEW_OCC) {
1019 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
1020 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
1022 AIS_ListOfInteractive List;
1023 ic->DisplayedObjects(List);
1024 AIS_ListOfInteractive List1;
1025 ic->ObjectsInCollector(List1);
1028 AIS_ListIteratorOfListOfInteractive ite(List);
1030 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1031 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1033 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
1034 Standard_CString theIOR = GIO->getIOR();
1035 if(strcmp(IOR, theIOR) == 0) {
1036 if(onlyInActiveView) {
1037 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1059 //=======================================================================
1060 // function : ConvertIORinGEOMActor()
1062 //=======================================================================
1063 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
1065 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1066 for(int i = 0; i < nbSf; i++) {
1067 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1068 if(sf->getTypeView() == VIEW_VTK) {
1069 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1070 vtkActorCollection* theActors = Renderer->GetActors();
1071 theActors->InitTraversal();
1072 vtkActor *ac = theActors->GetNextActor();
1073 while(!(ac==NULL)) {
1074 if( ac->IsA("GEOM_Actor")) {
1075 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
1076 if(anActor->hasIO()) {
1077 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(anActor->getIO());
1078 Standard_CString theIOR = GIO->getIOR();
1079 if(strcmp(IOR, theIOR) == 0) {
1080 if(onlyInActiveView) {
1081 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1093 ac = theActors->GetNextActor();
1098 return GEOM_Actor::New();
1102 //=======================================================================
1103 // function : ConvertIOinGEOMAISShape()
1105 //=======================================================================
1106 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
1108 Handle(GEOM_AISShape) res;
1109 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1110 for(int i = 0; i < nbSf; i++) {
1111 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1112 if(sf->getTypeView() == VIEW_OCC) {
1113 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
1114 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
1116 AIS_ListOfInteractive List;
1117 ic->DisplayedObjects(List);
1118 AIS_ListOfInteractive List1;
1119 ic->ObjectsInCollector(List1);
1122 AIS_ListIteratorOfListOfInteractive ite(List);
1124 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1125 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1127 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
1128 if(GIO->isSame(IO)) {
1129 if(onlyInActiveView) {
1130 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1151 //=======================================================================
1152 // function : ConvertIOinGEOMShape()
1154 //=======================================================================
1155 GEOM::GEOM_Shape_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
1157 GEOM::GEOM_Shape_var aShape;
1161 if(IO->hasEntry()) {
1162 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1163 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
1164 SALOMEDS::GenericAttribute_var anAttr;
1165 SALOMEDS::AttributeIOR_var anIOR;
1166 if(!obj->_is_nil()) {
1167 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
1168 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1169 aShape = myGeom->GetIORFromString(anIOR->Value());
1170 if(!CORBA::is_nil(aShape))
1172 return aShape._retn();
1176 /* case Graphical Object */
1177 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
1178 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
1179 Standard_CString ior = GIObject->getIOR();
1181 aShape = myGeom->GetIORFromString(ior);
1182 if(!CORBA::is_nil(aShape))
1184 return aShape._retn();
1186 return aShape._retn();
1190 //=======================================================================
1191 // function : ConvertListOfIOInListOfIOR()
1193 //=======================================================================
1194 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::GEOM_Gen::ListOfIOR& listIOR)
1196 int nbSel = aList.Extent();
1197 listIOR.length(nbSel);
1199 SALOME_ListIteratorOfListIO It(aList);
1200 for(int i=0; It.More(); It.Next(), i++) {
1201 Handle(SALOME_InteractiveObject) IObject = It.Value();
1202 if(IObject->hasEntry()) {
1203 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1204 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
1205 SALOMEDS::GenericAttribute_var anAttr;
1206 SALOMEDS::AttributeIOR_var anIOR;
1207 if(!obj->_is_nil() && obj->FindAttribute(anAttr, "AttributeIOR")) {
1208 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1209 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
1210 CORBA::ORB_var& _orb = init.orb();
1211 CORBA::String_var theValue = anIOR->Value();
1212 CORBA::Object_var theObj = _orb->string_to_object(theValue);
1213 if(theObj->_is_a("IDL:GEOM/GEOM_Shape:1.0")) {
1214 listIOR[j] = strdup(theValue);
1219 else if(IObject->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
1220 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IObject);
1221 Standard_CString ior = GIObject->getIOR();
1222 listIOR[j] = strdup(ior);
1230 //================================================================================
1231 // function : SetDisplayedObjectList()
1233 //================================================================================
1234 // void GEOMBase::SetDisplayedObjectList()
1236 // if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
1239 // OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1240 // myGeomGUI->GetListDisplayedObject().Clear();
1242 // Handle (AIS_InteractiveContext) aContext = v3d->getAISContext();
1243 // aContext->DisplayedObjects(myGeomGUI->GetListDisplayedObject());
1247 //=====================================================================================
1248 // function : DisplaySimulationShape()
1249 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
1250 //=====================================================================================
1251 void GEOMBase::DisplaySimulationShape(const TopoDS_Shape& S)
1256 //NRI DEBUG : 14/02/2002
1257 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
1260 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1261 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1263 /* erase any previous */
1264 ic->Erase(mySimulationShape, Standard_True, Standard_False);
1265 ic->ClearPrs(mySimulationShape);
1266 mySimulationShape = new AIS_Shape(TopoDS_Shape());
1267 mySimulationShape->Set(S);
1268 mySimulationShape->SetColor(Quantity_NOC_VIOLET);
1269 ic->Deactivate(mySimulationShape);
1270 ic->Display(mySimulationShape, Standard_False);
1271 ic->UpdateCurrentViewer();
1273 catch(Standard_Failure) {
1274 MESSAGE("Exception catched in GEOMBase::DisplaySimulationShape ");
1276 mySimulationShape->UnsetColor();
1281 //==================================================================================
1282 // function : EraseSimulationShape()
1283 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
1284 //==================================================================================
1285 void GEOMBase::EraseSimulationShape()
1287 int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1288 for(int i = 0; i < count; i++) {
1289 if(QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
1290 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
1291 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1292 ic->Erase(mySimulationShape, Standard_True, Standard_False);
1293 ic->ClearPrs(mySimulationShape);
1294 ic->UpdateCurrentViewer();
1300 //=================================================================================
1301 // function : CreateArrowForLinearEdge()
1302 // purpose : Create a cone topology to be used to display an arrow in the middle
1303 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
1304 //=================================================================================
1305 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
1307 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC || tds.ShapeType() != TopAbs_EDGE)
1310 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
1311 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
1312 Standard_Real Width, Height;
1313 view3d->Size(Width, Height);
1314 const Standard_Real aHeight = (Width + Height) / 50.0;
1317 Standard_Real first, last;
1318 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
1322 const Standard_Real param = (first+last) / 2.0;
1323 gp_Pnt middleParamPoint;
1325 curv->D1( param, middleParamPoint, V1);
1326 if(V1.Magnitude() < Precision::Confusion())
1329 /* Topology orientation not geom orientation */
1330 if(tds.Orientation() == TopAbs_REVERSED)
1333 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
1334 const Standard_Real radius1 = aHeight / 5.0;
1335 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
1336 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
1340 catch(Standard_Failure) {
1341 // OCC failures are hard to catch in GUI.
1342 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
1343 // in SALOME environment : compilation error !
1349 //=================================================================================
1350 // function : VertexToPoint()
1351 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
1352 //=================================================================================
1353 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
1355 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
1357 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
1362 //=================================================================================
1363 // function : GetBipointDxDyDz()
1365 //=================================================================================
1366 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
1368 dx = P2.X() - P1.X();
1369 dy = P2.Y() - P1.Y();
1370 dz = P2.Z() - P1.Z();
1375 //=================================================================================
1376 // function : LinearEdgeExtremities()
1377 // purpose : If S can be converted in a linear edge and if initial an final points
1378 // : distance is sufficient, returns true else returns false.
1379 // : Resulting points are respectively P1 and P2
1380 //=================================================================================
1381 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
1383 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
1385 BRepAdaptor_Curve curv(TopoDS::Edge(S));
1386 if(curv.GetType() != GeomAbs_Line)
1389 curv.D0(curv.FirstParameter(), P1);
1390 curv.D0(curv.LastParameter(), P2);
1392 if(P1.Distance(P2) <= Precision::Confusion())
1399 //=======================================================================
1400 // function : Parameter()
1401 // purpose : return a parameter (float) from a dialog box
1403 // avalue1 : is a float or integer used as a default value displayed
1404 // aTitle1 : is the title for aValue1
1405 // aTitle : is the main title
1406 // bottom : maximum value to be entered
1407 // top : minimum value to be entered
1408 // decimals : number of decimals
1409 //=======================================================================
1410 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
1412 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, QAD_Application::getDesktop(), aTitle, TRUE, 0, bottom, top, decimals);
1413 int r = Dialog->exec();
1415 if(r == QDialog::Accepted) {
1416 res = Standard_True;
1417 X = Dialog->getValue();
1420 res = Standard_False;
1426 //=======================================================================
1427 // function : SelectionByNameInDialogs()
1428 // purpose : Called when user has entered a name of object in a LineEdit.
1429 // : The selection is changed. Dialog box will receive the
1430 // : corresponding signal to manage this event.
1431 //=======================================================================
1432 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, SALOME_Selection* Sel)
1434 /* Find SObject with name in component GEOM */
1435 SALOMEDS::Study_var ST = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1436 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
1437 listSO = ST->FindObjectByName(objectUserName, "GEOM");
1439 if(listSO->length() < 1) {
1440 const QString caption = tr("GEOM_WRN_WARNING");
1441 const QString text = tr("GEOM_NAME_INCORRECT");
1442 const QString button0 = tr("GEOM_BUT_OK");
1443 QMessageBox::warning(aWidget, caption, text, button0);
1446 /* More than one object with same name */
1447 if(listSO->length() > 1) {
1448 const QString caption = tr("GEOM_WRN_WARNING");
1449 const QString text = tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
1450 const QString button0 = tr("GEOM_BUT_OK") ;
1451 QMessageBox::warning(aWidget, caption, text, button0) ;
1455 SALOMEDS::SObject_var theObj = listSO[0];
1456 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
1457 Standard_CString anEntry = theObj->GetID();
1458 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(anEntry, "GEOM", strdup(objectUserName));
1460 /* Add as a selected object */
1461 /* Clear any previous selection : */
1462 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
1463 Sel->ClearIObjects();
1464 Sel->AddIObject(SI);
1469 //=======================================================================
1470 // function : DefineDlgPosition()
1471 // purpose : Define x and y the default position for a dialog box
1472 //=======================================================================
1473 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
1475 /* Here the position is on the bottom right corner - 10 */
1476 QAD_Desktop* PP = QAD_Application::getDesktop();
1477 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1478 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1483 //=====================================================================================
1485 //=====================================================================================
1488 bool CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
1489 const QString & theParent, const QString & theObject)
1490 {return GEOMBase::CustomPopup(parent, popup, theContext, theParent, theObject);}