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 GEOM::GEOM_Shape_var aShape;
231 if(obj->FindAttribute(aTmpAttr, "AttributeIOR")) {
232 char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
233 if(str && strlen(str))
234 aShape = myGeomBase->myGeom->GetIORFromString(str);
236 else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
239 if(aShape->_is_nil()) {
240 SALOMEDS::ChildIterator_var anIter = ActiveStudy->getStudyDocument()->NewChildIterator(obj);
241 while(anIter->More()) {
242 SALOMEDS::SObject_var subobj = anIter->Value();
243 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
248 else if(subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) {
257 // remove useless popup items
259 popup->removeItem(901); // rename
261 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
264 int index = popup->indexOf(9024); // open
265 popup->removeItem(9024);
266 popup->removeItemAt(index); // separator under Open
269 popup->removeItem(QAD_Display_Popup_ID);
271 popup->removeItem(QAD_Erase_Popup_ID);
273 if(!needDisplay && !needErase) {
274 int id = popup->idAt(popup->count()-1); // last item
275 popup->removeItem(id); // separator
279 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
280 popup->removeItem(QAD_Display_Popup_ID);
281 popup->removeItem(QAD_Erase_Popup_ID);
283 int id = popup->idAt(popup->count()-1); // last item
284 popup->removeItem(id); // separator
290 else if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
291 // MESSAGE ( " CUSTOM POPUP VIEWER VTK ")
292 if((theParent.compare("Viewer") == 0)) {
293 popup->setItemEnabled(8034, false); //Isos Menu
294 if(theObject.compare("Component") == 0) {
295 popup->removeItem(QAD_DisplayOnly_Popup_ID);
299 //int id = popup->idAt(0);
300 QFont f = QApplication::font();
304 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
305 popup->removeItem(QAD_TopLabel_Popup_ID);
306 popup->insertItem(new CustomItem (QString(IObject->getName()), f), QAD_TopLabel_Popup_ID, 0);
307 if(IObject->hasEntry()) {
308 popup->setItemEnabled(804, false); //Add in Study Menu
309 SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
310 SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
311 SALOMEDS::GenericAttribute_var anAttr;
312 SALOMEDS::AttributeIOR_var anIOR;
314 if(SO->FindAttribute(anAttr, "AttributeIOR")) {
315 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
316 Standard_Boolean found;
317 GEOM_Actor* Result = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), found, true);
319 if(Result->getDisplayMode() == 1)
320 popup->changeItem(8031, tr("GEOM_MEN_WIREFRAME")); //Shading/Wireframe Menu
322 popup->changeItem(8031, tr("GEOM_MEN_SHADING")); //Shading/Wireframe Menu
324 if(!Result->GetVisibility())
325 popup->removeItem(QAD_Erase_Popup_ID);
327 popup->removeItem(QAD_Display_Popup_ID);
330 popup->removeItem(QAD_Erase_Popup_ID);
335 popup->setItemEnabled(804, true); //Add in Study Menu
338 popup->removeItem(QAD_DisplayOnly_Popup_ID);
339 popup->removeItem(QAD_TopLabel_Popup_ID);
340 popup->insertItem( new CustomItem (tr("GEOM_MEN_POPUP_NAME").arg(nbSel), f), QAD_TopLabel_Popup_ID, 0);
341 popup->setItemEnabled(804, false); //Add in Study Menu
345 else if(theParent.compare("ObjectBrowser") == 0) {
346 popup->removeItem(QAD_TopLabel_Popup_ID);
347 int id = popup->idAt(0); // separator
349 popup->removeItem(id);
351 // checking for GEOM label in the selected list
352 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
353 Handle(SALOME_InteractiveObject) anIObject;
355 bool useSubItems = false;
356 bool needOpen = false;
357 bool needDisplay = false;
358 bool needErase = false;
359 SALOMEDS::GenericAttribute_var aTmpAttr;
360 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
361 for(;It.More();It.Next()) {
362 anIObject = It.Value();
363 if(!anIObject->hasEntry())
366 if(myRenderInter->isInViewer(anIObject) && myRenderInter->isVisible(anIObject))
371 SALOMEDS::SObject_var obj = ActiveStudy->getStudyDocument()->FindObjectID(anIObject->getEntry());
372 if(!obj->_is_nil()) {
373 GEOM::GEOM_Shape_var aShape;
374 if(obj->FindAttribute(aTmpAttr, "AttributeIOR")) {
375 char *str = SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value();
376 if(str && strlen(str))
377 aShape = myGeomBase->myGeom->GetIORFromString(str);
379 else if(obj->FindAttribute(aTmpAttr, "AttributePersistentRef"))
382 if(aShape->_is_nil()) {
383 SALOMEDS::ChildIterator_var anIter = ActiveStudy->getStudyDocument()->NewChildIterator(obj);
384 while(anIter->More()) {
385 SALOMEDS::SObject_var subobj = anIter->Value();
386 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
391 else if(subobj->FindAttribute(aTmpAttr, "AttributePersistentRef")) {
400 // remove useless popup items
402 popup->removeItem(901); // rename
404 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
407 int index = popup->indexOf(9024); // open
408 popup->removeItem(9024);
409 popup->removeItemAt(index); // separator under Open
412 popup->removeItem(QAD_Display_Popup_ID);
414 popup->removeItem(QAD_Erase_Popup_ID);
415 if(!needDisplay && !needErase) {
416 int id = popup->idAt(popup->count()-1); // last item
417 popup->removeItem(id); // separator
421 popup->removeItem(QAD_DisplayOnly_Popup_ID); // display only
422 popup->removeItem(QAD_Display_Popup_ID);
423 popup->removeItem(QAD_Erase_Popup_ID);
425 int id = popup->idAt(popup->count()-1); // last item
426 popup->removeItem(id); // separator
432 else { // other viewer types not supported.
434 int id = popup->idAt(0);
435 if(id <= QAD_TopLabel_Popup_ID && id != -1)
436 popup->removeItemAt(0);
440 popup->removeItem(QAD_DisplayOnly_Popup_ID);
441 popup->removeItem(QAD_Display_Popup_ID);
442 popup->removeItem(QAD_Erase_Popup_ID);
443 int id = popup->idAt(popup->count() - 1); // last item
444 if(id < 0 && id != -1)
445 popup->removeItem(id); // separator
452 //=====================================================================================
453 // function : Display()
454 // purpose : Displays a CORBA shape
455 //=====================================================================================
456 bool GEOMBase::Display(GEOM::GEOM_Shape_ptr aShape, Standard_CString name)
458 // MESSAGE ( "GEOMBase::Display init ")
459 Handle(GEOM_InteractiveObject) IO;
460 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
461 Sel->ClearIObjects();
463 if(aShape->_is_nil()) {
464 QAD_MessageBox::warn1 (QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_PRP_ABORT"), tr("GEOM_BUT_OK"));
468 TopoDS_Shape shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
472 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
473 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
474 SALOMEDS::GenericAttribute_var anAttr;
475 SALOMEDS::AttributeName_var aName;
476 SALOMEDS::AttributePixMap_var aPixmap;
478 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
480 if(father->_is_nil()) {
481 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
483 aLocked = aStudy->GetProperties()->IsLocked();
485 aStudy->GetProperties()->SetLocked(false);
486 father = aStudyBuilder->NewComponent("GEOM");
487 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
488 aName = SALOMEDS::AttributeName::_narrow(anAttr);
489 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName("GEOM"));
490 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
491 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
492 aPixmap->SetPixMap("ICON_OBJBROWSER_Geometry");
493 aStudyBuilder->DefineComponentInstance(father, myGeom);
494 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
496 aStudy->GetProperties()->SetLocked(true);
500 father->ComponentIOR(myGeomGUI->GetFatherior());
502 TCollection_AsciiString nameG("");
503 Standard_CString Type;
504 if(TCollection_AsciiString(name).IsEqual(Standard_CString(""))) {
505 if(TCollection_AsciiString(aShape->NameType()).IsEqual(Standard_CString(""))) {
506 Standard_CString type;
507 GetShapeTypeString(shape,type);
508 aShape->NameType(type);
509 nameG += TCollection_AsciiString(type) + TCollection_AsciiString("_") + TCollection_AsciiString(myGeomGUI->GetNbGeom()++) + TCollection_AsciiString("\0");
512 nameG += TCollection_AsciiString(aShape->NameType()) + TCollection_AsciiString("_") + TCollection_AsciiString(myGeomGUI->GetNbGeom()++) + TCollection_AsciiString("\0");
515 nameG = TCollection_AsciiString(name);
518 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
519 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
521 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
522 int themode = myRenderInter->GetDisplayMode();
524 vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(shape, 0, themode, Standard_True);
525 theActors->InitTraversal();
526 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
528 IO = new GEOM_InteractiveObject(aShape->Name(), myGeomGUI->GetFatherior(), "GEOM");
529 while(!(anActor==NULL)) {
530 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
532 GActor->setName(nameG.ToCString());
534 theRenderer->AddActor(GActor);
535 anActor = (vtkActor*)theActors->GetNextActor();
539 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
540 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
541 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
542 Handle(GEOM_AISShape) theResult = new GEOM_AISShape(shape, nameG.ToCString());
543 theResult->SetInfiniteState(shape.Infinite());
544 theResult->SetShadingColor(myShadingColor);
545 IO = new GEOM_InteractiveObject(aShape->Name(), myGeomGUI->GetFatherior(), "GEOM");
546 theResult->setIO(IO);
547 theResult->setName(nameG.ToCString());
549 /* Precaution : close any local context to permit the display */
550 if(ic->HasOpenedContext())
551 ic->CloseAllContexts();
553 ic->Display(theResult);
556 // DCQ Sel->AddIObject(IO, false);
557 QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
558 if(mySettings_AddInStudy)
559 AddInStudy(false, IO);
565 //=====================================================================================
566 // function : AddInStudy()
567 // purpose : anIOShape or a selected shape
568 //=====================================================================================
569 bool GEOMBase::AddInStudy(bool selection, const Handle(SALOME_InteractiveObject)& anIO)
571 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
572 if (!(!mySettings_AddInStudy || selection)) {
573 Sel->ClearIObjects();
576 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
577 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
578 SALOMEDS::GenericAttribute_var anAttr;
579 SALOMEDS::AttributeName_var aName;
580 SALOMEDS::AttributePixMap_var aPixmap;
581 SALOMEDS::AttributeIOR_var anIOR;
582 SALOMEDS::AttributeSelectable_var aSelAttr;
584 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
586 if(father->_is_nil()) {
587 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
589 aLocked = aStudy->GetProperties()->IsLocked();
591 aStudy->GetProperties()->SetLocked(false);
592 father = aStudyBuilder->NewComponent("GEOM");
593 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
594 aName = SALOMEDS::AttributeName::_narrow(anAttr);
595 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName("GEOM"));
596 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
597 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
598 aPixmap->SetPixMap("ICON_OBJBROWSER_Geometry");
599 aStudyBuilder->DefineComponentInstance(father, myGeom);
601 aStudy->GetProperties()->SetLocked(true);
605 father->ComponentIOR(myGeomGUI->GetFatherior());
607 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
609 Handle(GEOM_AISShape) GAISShape;
611 Handle(GEOM_InteractiveObject) GIO;
615 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
616 vtkRenderer *Renderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
618 vtkActorCollection* theActors = Renderer->GetActors();
619 theActors->InitTraversal();
620 vtkActor *ac = theActors->GetNextActor();
622 if(ac->IsA("GEOM_Actor")) {
623 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
624 if(anActor->hasIO()) {
625 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
626 if(IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
627 GIO = Handle(GEOM_InteractiveObject)::DownCast(IO);
628 if(anIO->isSame(GIO)) {
636 ac = theActors->GetNextActor();
643 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
644 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
645 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
647 AIS_ListOfInteractive List;
648 ic->DisplayedObjects(List);
649 AIS_ListIteratorOfListOfInteractive ite(List);
651 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
652 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
654 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
655 if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
656 GIO = Handle(GEOM_InteractiveObject)::DownCast(IO);
657 if(anIO->isSame(GIO)) {
672 if(!mySettings_AddInStudy || selection) {
673 QString Name = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), anIO->getName());
674 if(!Name.isEmpty()) {
676 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
677 GActor->setName(strdup(Name.latin1()));
679 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
680 GAISShape->setName(strdup(Name.latin1()));
687 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
690 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
692 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(GIO->getIOR());
694 /* For the shape inserted into the study we set its field 'studyshapeid' */
695 /* so the shape will contain its corresponding entry in the study Ocaf doc. */
696 aShape->StudyShapeId(newObj->GetID());
698 GIO->setEntry(newObj->GetID());
700 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
701 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
702 anIOR->SetValue(aShape->Name());
704 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
705 aName = SALOMEDS::AttributeName::_narrow(anAttr);
707 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
708 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
709 if(aShape->ShapeType() == GEOM::COMPOUND)
710 aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
711 else if(aShape->ShapeType() == GEOM::COMPSOLID)
712 aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
713 else if(aShape->ShapeType() == GEOM::SOLID)
714 aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
715 else if(aShape->ShapeType() == GEOM::SHELL)
716 aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
717 else if(aShape->ShapeType() == GEOM::FACE)
718 aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
719 else if(aShape->ShapeType() == GEOM::WIRE)
720 aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
721 else if(aShape->ShapeType() == GEOM::EDGE)
722 aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
723 else if(aShape->ShapeType() == GEOM::VERTEX)
724 aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
727 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
729 aName->SetValue(GActor->getName());
732 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
733 GAISShape->setIO(GIO);
734 aName->SetValue(GAISShape->getName());
737 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
738 aStudyBuilder->Addreference(newObj1,newObj);
740 GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
741 listIOR = myGeom->GetReferencedObjects(aShape);
743 if(listIOR->length()>0) {
744 SALOMEDS::SObject_var Arguments = aStudyBuilder->NewObject(newObj);
745 anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeName");
746 aName = SALOMEDS::AttributeName::_narrow(anAttr);
747 aName->SetValue(tr("GEOM_ARGUMENTS"));
748 anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeSelectable");
749 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
750 aSelAttr->SetSelectable(false);
752 bool ObjectReferenced = false;
753 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
754 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(listIOR[ind]);
756 if(!theObj->_is_nil()) {
757 SALOMEDS::SObject_var RefObject = aStudyBuilder->NewObject(Arguments);
758 aStudyBuilder->Addreference(RefObject, theObj);
759 ObjectReferenced = true;
763 if(!ObjectReferenced)
764 aStudyBuilder->RemoveObject(Arguments);
768 if(!mySettings_AddInStudy || selection)
769 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
771 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(false);
772 // DCQ Sel->AddIObject(GIO);
778 //=====================================================================================
779 // function : GetShapeFromIOR()
780 // purpose : exist also as static method !
781 //=====================================================================================
782 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
785 if(IOR.stripWhiteSpace().isEmpty())
787 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
788 CORBA::ORB_var& _orb = init.orb() ;
789 CORBA::Object_var obj = _orb->string_to_object((char*)(IOR.latin1()));
790 if(CORBA::is_nil(obj))
792 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(IOR);
793 if(!aShape->_is_nil())
794 result = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
799 //=====================================================================================
800 // function : GetIndex()
801 // purpose : Get the index of a sub shape in a main shape : index start at 1
802 //=====================================================================================
803 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
805 if(shape.IsNull() || subshape.IsNull())
809 if(subshape.ShapeType() == TopAbs_COMPOUND) {
811 TopTools_ListOfShape CL;
813 TopTools_ListIteratorOfListOfShape itC;
814 for(itC.Initialize(CL); itC.More(); itC.Next()) {
815 for(it.Initialize(itC.Value()); it.More(); it.Next()) {
816 if(it.Value().ShapeType() == TopAbs_COMPOUND) {
817 if(it.Value().IsSame(subshape))
821 CL.Append(it.Value());
827 TopExp_Explorer Exp(shape, subshape.ShapeType());
828 TopTools_MapOfShape M;
830 if(M.Add(Exp.Current())) {
831 if(Exp.Current().IsSame(subshape))
842 //=======================================================================
843 // function : GetTopoFromSelection()
844 // purpose : Define tds from a single selection and retuen true
845 //=======================================================================
846 bool GEOMBase::GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds)
848 if(Sel->IObjectCount() != 1)
851 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
854 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
855 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
856 SALOMEDS::GenericAttribute_var anAttr;
857 SALOMEDS::AttributeIOR_var anIOR;
858 if(!obj->_is_nil()) {
859 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
860 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
861 tds = this->GetShapeFromIOR(anIOR->Value());
870 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
871 Standard_CString ior = "";
872 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
873 ior = GIObject->getIOR();
874 tds = this->GetShapeFromIOR(ior);
885 //=======================================================================
886 // function : GetNameOfSelectedIObjects()
887 // purpose : Define the name geom++ or other name of mono or multi sel.
888 //=======================================================================
889 int GEOMBase::GetNameOfSelectedIObjects(SALOME_Selection* Sel, QString& aName)
891 int nbSel = Sel->IObjectCount();
893 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
894 aName = IObject->getName();
897 aName = tr("%1_objects").arg(nbSel);
903 //=================================================================================
904 // function : GetShapeTypeString()
905 // purpose : for a single shape
906 //=================================================================================
907 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
909 if(aShape.IsNull()) {
910 aTypeString = "aNullShape";
913 switch(aShape.ShapeType())
915 case TopAbs_COMPOUND:
917 aTypeString = strdup(tr("GEOM_COMPOUND"));
920 case TopAbs_COMPSOLID:
922 aTypeString = strdup(tr("GEOM_COMPOUNDSOLID")) ;
927 aTypeString = strdup(tr("GEOM_SOLID")) ;
932 aTypeString = strdup(tr("GEOM_SHELL")) ;
937 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
938 if(surf.GetType() == GeomAbs_Plane) {
939 aTypeString = strdup(tr("GEOM_PLANE"));
942 else if(surf.GetType() == GeomAbs_Cylinder) {
943 aTypeString = strdup(tr("GEOM_SURFCYLINDER"));
946 else if(surf.GetType() == GeomAbs_Sphere) {
947 aTypeString = strdup(tr("GEOM_SURFSPHERE"));
950 else if(surf.GetType() == GeomAbs_Torus) {
951 aTypeString = strdup(tr("GEOM_SURFTORUS"));
954 else if(surf.GetType() == GeomAbs_Cone) {
955 aTypeString = strdup(tr("GEOM_SURFCONE"));
959 aTypeString = strdup(tr("GEOM_FACE"));
965 aTypeString = strdup(tr("GEOM_WIRE"));
970 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
971 if(curv.GetType() == GeomAbs_Line) {
972 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
973 aTypeString = strdup(tr("GEOM_LINE"));
975 aTypeString = strdup(tr("GEOM_EDGE"));
978 else if(curv.GetType() == GeomAbs_Circle) {
980 aTypeString = strdup(tr("GEOM_CIRCLE"));
982 aTypeString = strdup(tr("GEOM_ARC"));
986 aTypeString = strdup(tr("GEOM_EDGE"));
992 aTypeString = strdup(tr("GEOM_VERTEX"));
997 aTypeString = strdup(tr("GEOM_SHAPE"));
1005 //=======================================================================
1006 // function : ConvertIORinGEOMAISShape()
1008 //=======================================================================
1009 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
1011 Handle(GEOM_AISShape) resultShape;
1013 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1014 for(int i = 0; i < nbSf; i++) {
1015 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1016 if(sf->getTypeView() == VIEW_OCC) {
1017 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
1018 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
1020 AIS_ListOfInteractive List;
1021 ic->DisplayedObjects(List);
1022 AIS_ListOfInteractive List1;
1023 ic->ObjectsInCollector(List1);
1026 AIS_ListIteratorOfListOfInteractive ite(List);
1028 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1029 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1031 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
1032 Standard_CString theIOR = GIO->getIOR();
1033 if(strcmp(IOR, theIOR) == 0) {
1034 if(onlyInActiveView) {
1035 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1057 //=======================================================================
1058 // function : ConvertIORinGEOMActor()
1060 //=======================================================================
1061 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
1063 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1064 for(int i = 0; i < nbSf; i++) {
1065 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1066 if(sf->getTypeView() == VIEW_VTK) {
1067 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1068 vtkActorCollection* theActors = Renderer->GetActors();
1069 theActors->InitTraversal();
1070 vtkActor *ac = theActors->GetNextActor();
1071 while(!(ac==NULL)) {
1072 if( ac->IsA("GEOM_Actor")) {
1073 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
1074 if(anActor->hasIO()) {
1075 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(anActor->getIO());
1076 Standard_CString theIOR = GIO->getIOR();
1077 if(strcmp(IOR, theIOR) == 0) {
1078 if(onlyInActiveView) {
1079 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1091 ac = theActors->GetNextActor();
1096 return GEOM_Actor::New();
1100 //=======================================================================
1101 // function : ConvertIOinGEOMAISShape()
1103 //=======================================================================
1104 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
1106 Handle(GEOM_AISShape) res;
1107 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1108 for(int i = 0; i < nbSf; i++) {
1109 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1110 if(sf->getTypeView() == VIEW_OCC) {
1111 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
1112 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
1114 AIS_ListOfInteractive List;
1115 ic->DisplayedObjects(List);
1116 AIS_ListOfInteractive List1;
1117 ic->ObjectsInCollector(List1);
1120 AIS_ListIteratorOfListOfInteractive ite(List);
1122 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1123 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1125 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
1126 if(GIO->isSame(IO)) {
1127 if(onlyInActiveView) {
1128 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1149 //=======================================================================
1150 // function : ConvertIOinGEOMShape()
1152 //=======================================================================
1153 GEOM::GEOM_Shape_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
1155 GEOM::GEOM_Shape_var aShape;
1159 if(IO->hasEntry()) {
1160 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1161 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
1162 SALOMEDS::GenericAttribute_var anAttr;
1163 SALOMEDS::AttributeIOR_var anIOR;
1164 if(!obj->_is_nil()) {
1165 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
1166 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1167 aShape = myGeom->GetIORFromString(anIOR->Value());
1168 if(!CORBA::is_nil(aShape))
1170 return aShape._retn();
1174 /* case Graphical Object */
1175 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
1176 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
1177 Standard_CString ior = GIObject->getIOR();
1179 aShape = myGeom->GetIORFromString(ior);
1180 if(!CORBA::is_nil(aShape))
1182 return aShape._retn();
1184 return aShape._retn();
1188 //=======================================================================
1189 // function : ConvertListOfIOInListOfIOR()
1191 //=======================================================================
1192 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::GEOM_Gen::ListOfIOR& listIOR)
1194 int nbSel = aList.Extent();
1195 listIOR.length(nbSel);
1197 SALOME_ListIteratorOfListIO It(aList);
1198 for(int i=0; It.More(); It.Next(), i++) {
1199 Handle(SALOME_InteractiveObject) IObject = It.Value();
1200 if(IObject->hasEntry()) {
1201 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1202 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
1203 SALOMEDS::GenericAttribute_var anAttr;
1204 SALOMEDS::AttributeIOR_var anIOR;
1205 if(!obj->_is_nil() && obj->FindAttribute(anAttr, "AttributeIOR")) {
1206 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1207 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
1208 CORBA::ORB_var& _orb = init.orb();
1209 CORBA::String_var theValue = anIOR->Value();
1210 CORBA::Object_var theObj = _orb->string_to_object(theValue);
1211 if(theObj->_is_a("IDL:GEOM/GEOM_Shape:1.0")) {
1212 listIOR[j] = strdup(theValue);
1217 else if(IObject->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
1218 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IObject);
1219 Standard_CString ior = GIObject->getIOR();
1220 listIOR[j] = strdup(ior);
1228 //================================================================================
1229 // function : SetDisplayedObjectList()
1231 //================================================================================
1232 // void GEOMBase::SetDisplayedObjectList()
1234 // if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
1237 // OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1238 // myGeomGUI->GetListDisplayedObject().Clear();
1240 // Handle (AIS_InteractiveContext) aContext = v3d->getAISContext();
1241 // aContext->DisplayedObjects(myGeomGUI->GetListDisplayedObject());
1245 //=====================================================================================
1246 // function : DisplaySimulationShape()
1247 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
1248 //=====================================================================================
1249 void GEOMBase::DisplaySimulationShape(const TopoDS_Shape& S)
1254 //NRI DEBUG : 14/02/2002
1255 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
1258 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1259 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1261 /* erase any previous */
1262 ic->Erase(mySimulationShape, Standard_True, Standard_False);
1263 ic->ClearPrs(mySimulationShape);
1264 mySimulationShape = new AIS_Shape(TopoDS_Shape());
1265 mySimulationShape->Set(S);
1266 mySimulationShape->SetColor(Quantity_NOC_VIOLET);
1267 ic->Deactivate(mySimulationShape);
1268 ic->Display(mySimulationShape, Standard_False);
1269 ic->UpdateCurrentViewer();
1271 catch(Standard_Failure) {
1272 MESSAGE("Exception catched in GEOMBase::DisplaySimulationShape ");
1274 mySimulationShape->UnsetColor();
1279 //==================================================================================
1280 // function : EraseSimulationShape()
1281 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
1282 //==================================================================================
1283 void GEOMBase::EraseSimulationShape()
1285 int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1286 for(int i = 0; i < count; i++) {
1287 if(QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
1288 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
1289 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1290 ic->Erase(mySimulationShape, Standard_True, Standard_False);
1291 ic->ClearPrs(mySimulationShape);
1292 ic->UpdateCurrentViewer();
1298 //=================================================================================
1299 // function : CreateArrowForLinearEdge()
1300 // purpose : Create a cone topology to be used to display an arrow in the middle
1301 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
1302 //=================================================================================
1303 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
1305 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC || tds.ShapeType() != TopAbs_EDGE)
1308 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
1309 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
1310 Standard_Real Width, Height;
1311 view3d->Size(Width, Height);
1312 const Standard_Real aHeight = (Width + Height) / 50.0;
1315 Standard_Real first, last;
1316 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
1320 const Standard_Real param = (first+last) / 2.0;
1321 gp_Pnt middleParamPoint;
1323 curv->D1( param, middleParamPoint, V1);
1324 if(V1.Magnitude() < Precision::Confusion())
1327 /* Topology orientation not geom orientation */
1328 if(tds.Orientation() == TopAbs_REVERSED)
1331 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
1332 const Standard_Real radius1 = aHeight / 5.0;
1333 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
1334 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
1338 catch(Standard_Failure) {
1339 // OCC failures are hard to catch in GUI.
1340 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
1341 // in SALOME environment : compilation error !
1347 //=================================================================================
1348 // function : VertexToPoint()
1349 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
1350 //=================================================================================
1351 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
1353 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
1355 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
1360 //=================================================================================
1361 // function : GetBipointDxDyDz()
1363 //=================================================================================
1364 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
1366 dx = P2.X() - P1.X();
1367 dy = P2.Y() - P1.Y();
1368 dz = P2.Z() - P1.Z();
1373 //=================================================================================
1374 // function : LinearEdgeExtremities()
1375 // purpose : If S can be converted in a linear edge and if initial an final points
1376 // : distance is sufficient, returns true else returns false.
1377 // : Resulting points are respectively P1 and P2
1378 //=================================================================================
1379 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
1381 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
1383 BRepAdaptor_Curve curv(TopoDS::Edge(S));
1384 if(curv.GetType() != GeomAbs_Line)
1387 curv.D0(curv.FirstParameter(), P1);
1388 curv.D0(curv.LastParameter(), P2);
1390 if(P1.Distance(P2) <= Precision::Confusion())
1397 //=======================================================================
1398 // function : Parameter()
1399 // purpose : return a parameter (float) from a dialog box
1401 // avalue1 : is a float or integer used as a default value displayed
1402 // aTitle1 : is the title for aValue1
1403 // aTitle : is the main title
1404 // bottom : maximum value to be entered
1405 // top : minimum value to be entered
1406 // decimals : number of decimals
1407 //=======================================================================
1408 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
1410 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, QAD_Application::getDesktop(), aTitle, TRUE, 0, bottom, top, decimals);
1411 int r = Dialog->exec();
1413 if(r == QDialog::Accepted) {
1414 res = Standard_True;
1415 X = Dialog->getValue();
1418 res = Standard_False;
1424 //=======================================================================
1425 // function : SelectionByNameInDialogs()
1426 // purpose : Called when user has entered a name of object in a LineEdit.
1427 // : The selection is changed. Dialog box will receive the
1428 // : corresponding signal to manage this event.
1429 //=======================================================================
1430 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, SALOME_Selection* Sel)
1432 /* Find SObject with name in component GEOM */
1433 SALOMEDS::Study_var ST = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1434 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
1435 listSO = ST->FindObjectByName(objectUserName, "GEOM");
1437 if(listSO->length() < 1) {
1438 const QString caption = tr("GEOM_WRN_WARNING");
1439 const QString text = tr("GEOM_NAME_INCORRECT");
1440 const QString button0 = tr("GEOM_BUT_OK");
1441 QMessageBox::warning(aWidget, caption, text, button0);
1444 /* More than one object with same name */
1445 if(listSO->length() > 1) {
1446 const QString caption = tr("GEOM_WRN_WARNING");
1447 const QString text = tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
1448 const QString button0 = tr("GEOM_BUT_OK") ;
1449 QMessageBox::warning(aWidget, caption, text, button0) ;
1453 SALOMEDS::SObject_var theObj = listSO[0];
1454 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
1455 Standard_CString anEntry = theObj->GetID();
1456 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(anEntry, "GEOM", strdup(objectUserName));
1458 /* Add as a selected object */
1459 /* Clear any previous selection : */
1460 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
1461 Sel->ClearIObjects();
1462 Sel->AddIObject(SI);
1467 //=======================================================================
1468 // function : DefineDlgPosition()
1469 // purpose : Define x and y the default position for a dialog box
1470 //=======================================================================
1471 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
1473 /* Here the position is on the bottom right corner - 10 */
1474 QAD_Desktop* PP = QAD_Application::getDesktop();
1475 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1476 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1481 //=====================================================================================
1483 //=====================================================================================
1486 bool CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
1487 const QString & theParent, const QString & theObject)
1488 {return GEOMBase::CustomPopup(parent, popup, theContext, theParent, theObject);}