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 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
495 aStudy->GetProperties()->SetLocked(true);
499 aStudyBuilder->DefineComponentInstance(father, myGeom);
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->SetShadingColor(myShadingColor);
544 IO = new GEOM_InteractiveObject(aShape->Name(), myGeomGUI->GetFatherior(), "GEOM");
545 theResult->setIO(IO);
546 theResult->setName(nameG.ToCString());
548 /* Precaution : close any local context to permit the display */
549 if(ic->HasOpenedContext())
550 ic->CloseAllContexts();
552 ic->Display(theResult);
555 // DCQ Sel->AddIObject(IO, false);
556 QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
557 if(mySettings_AddInStudy)
558 AddInStudy(false, IO);
564 //=====================================================================================
565 // function : AddInStudy()
566 // purpose : anIOShape or a selected shape
567 //=====================================================================================
568 bool GEOMBase::AddInStudy(bool selection, const Handle(SALOME_InteractiveObject)& anIO)
570 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
571 if (!(!mySettings_AddInStudy || selection)) {
572 Sel->ClearIObjects();
575 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
576 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
577 SALOMEDS::GenericAttribute_var anAttr;
578 SALOMEDS::AttributeName_var aName;
579 SALOMEDS::AttributePixMap_var aPixmap;
580 SALOMEDS::AttributeIOR_var anIOR;
581 SALOMEDS::AttributeSelectable_var aSelAttr;
583 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
585 if(father->_is_nil()) {
586 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
588 aLocked = aStudy->GetProperties()->IsLocked();
590 aStudy->GetProperties()->SetLocked(false);
591 father = aStudyBuilder->NewComponent("GEOM");
592 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
593 aName = SALOMEDS::AttributeName::_narrow(anAttr);
594 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName("GEOM"));
595 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
596 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
597 aPixmap->SetPixMap("ICON_OBJBROWSER_Geometry");
599 aStudy->GetProperties()->SetLocked(true);
603 aStudyBuilder->DefineComponentInstance(father, myGeom);
604 father->ComponentIOR(myGeomGUI->GetFatherior());
606 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
608 Handle(GEOM_AISShape) GAISShape;
610 Handle(GEOM_InteractiveObject) GIO;
614 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
615 vtkRenderer *Renderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
617 vtkActorCollection* theActors = Renderer->GetActors();
618 theActors->InitTraversal();
619 vtkActor *ac = theActors->GetNextActor();
621 if(ac->IsA("GEOM_Actor")) {
622 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
623 if(anActor->hasIO()) {
624 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
625 if(IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
626 GIO = Handle(GEOM_InteractiveObject)::DownCast(IO);
627 if(anIO->isSame(GIO)) {
635 ac = theActors->GetNextActor();
642 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
643 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
644 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
646 AIS_ListOfInteractive List;
647 ic->DisplayedObjects(List);
648 AIS_ListIteratorOfListOfInteractive ite(List);
650 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
651 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
653 Handle(SALOME_InteractiveObject) IO = aSh->getIO();
654 if ( IO->IsKind(STANDARD_TYPE(GEOM_InteractiveObject))) {
655 GIO = Handle(GEOM_InteractiveObject)::DownCast(IO);
656 if(anIO->isSame(GIO)) {
671 if(!mySettings_AddInStudy || selection) {
672 QString Name = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), anIO->getName());
673 if(!Name.isEmpty()) {
675 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
676 GActor->setName(strdup(Name.latin1()));
678 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
679 GAISShape->setName(strdup(Name.latin1()));
686 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
689 SALOMEDS::SObject_var newObj = aStudyBuilder->NewObject(father);
691 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(GIO->getIOR());
693 /* For the shape inserted into the study we set its field 'studyshapeid' */
694 /* so the shape will contain its corresponding entry in the study Ocaf doc. */
695 aShape->StudyShapeId(newObj->GetID());
697 GIO->setEntry(newObj->GetID());
699 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
700 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
701 anIOR->SetValue(aShape->Name());
703 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributeName");
704 aName = SALOMEDS::AttributeName::_narrow(anAttr);
706 anAttr = aStudyBuilder->FindOrCreateAttribute(newObj, "AttributePixMap");
707 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
708 if(aShape->ShapeType() == GEOM::COMPOUND)
709 aPixmap->SetPixMap("ICON_OBJBROWSER_COMPOUND");
710 else if(aShape->ShapeType() == GEOM::COMPSOLID)
711 aPixmap->SetPixMap("ICON_OBJBROWSER_COMPSOLID");
712 else if(aShape->ShapeType() == GEOM::SOLID)
713 aPixmap->SetPixMap("ICON_OBJBROWSER_SOLID");
714 else if(aShape->ShapeType() == GEOM::SHELL)
715 aPixmap->SetPixMap("ICON_OBJBROWSER_SHELL");
716 else if(aShape->ShapeType() == GEOM::FACE)
717 aPixmap->SetPixMap("ICON_OBJBROWSER_FACE");
718 else if(aShape->ShapeType() == GEOM::WIRE)
719 aPixmap->SetPixMap("ICON_OBJBROWSER_WIRE");
720 else if(aShape->ShapeType() == GEOM::EDGE)
721 aPixmap->SetPixMap("ICON_OBJBROWSER_EDGE");
722 else if(aShape->ShapeType() == GEOM::VERTEX)
723 aPixmap->SetPixMap("ICON_OBJBROWSER_VERTEX");
726 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
728 aName->SetValue(GActor->getName());
731 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
732 GAISShape->setIO(GIO);
733 aName->SetValue(GAISShape->getName());
736 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
737 aStudyBuilder->Addreference(newObj1,newObj);
739 GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
740 listIOR = myGeom->GetReferencedObjects(aShape);
742 if(listIOR->length()>0) {
743 SALOMEDS::SObject_var Arguments = aStudyBuilder->NewObject(newObj);
744 anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeName");
745 aName = SALOMEDS::AttributeName::_narrow(anAttr);
746 aName->SetValue(tr("GEOM_ARGUMENTS"));
747 anAttr = aStudyBuilder->FindOrCreateAttribute(Arguments, "AttributeSelectable");
748 aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr);
749 aSelAttr->SetSelectable(false);
751 bool ObjectReferenced = false;
752 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
753 SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(listIOR[ind]);
755 if(!theObj->_is_nil()) {
756 SALOMEDS::SObject_var RefObject = aStudyBuilder->NewObject(Arguments);
757 aStudyBuilder->Addreference(RefObject, theObj);
758 ObjectReferenced = true;
762 if(!ObjectReferenced)
763 aStudyBuilder->RemoveObject(Arguments);
767 if(!mySettings_AddInStudy || selection)
768 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
770 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(false);
771 // DCQ Sel->AddIObject(GIO);
777 //=====================================================================================
778 // function : GetShapeFromIOR()
779 // purpose : exist also as static method !
780 //=====================================================================================
781 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
784 if(IOR.stripWhiteSpace().isEmpty())
786 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
787 CORBA::ORB_var& _orb = init.orb() ;
788 CORBA::Object_var obj = _orb->string_to_object((char*)(IOR.latin1()));
789 if(CORBA::is_nil(obj))
791 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(IOR);
792 if(!aShape->_is_nil())
793 result = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
798 //=====================================================================================
799 // function : GetIndex()
800 // purpose : Get the index of a sub shape in a main shape : index start at 1
801 //=====================================================================================
802 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
804 if(shape.IsNull() || subshape.IsNull())
808 if(subshape.ShapeType() == TopAbs_COMPOUND) {
810 TopTools_ListOfShape CL;
812 TopTools_ListIteratorOfListOfShape itC;
813 for(itC.Initialize(CL); itC.More(); itC.Next()) {
814 for(it.Initialize(itC.Value()); it.More(); it.Next()) {
815 if(it.Value().ShapeType() == TopAbs_COMPOUND) {
816 if(it.Value().IsSame(subshape))
820 CL.Append(it.Value());
826 TopExp_Explorer Exp(shape, subshape.ShapeType());
827 TopTools_MapOfShape M;
829 if(M.Add(Exp.Current())) {
830 if(Exp.Current().IsSame(subshape))
841 //=======================================================================
842 // function : GetTopoFromSelection()
843 // purpose : Define tds from a single selection and retuen true
844 //=======================================================================
845 bool GEOMBase::GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds)
847 if(Sel->IObjectCount() != 1)
850 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
853 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
854 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
855 SALOMEDS::GenericAttribute_var anAttr;
856 SALOMEDS::AttributeIOR_var anIOR;
857 if(!obj->_is_nil()) {
858 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
859 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
860 tds = this->GetShapeFromIOR(anIOR->Value());
869 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
870 Standard_CString ior = "";
871 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
872 ior = GIObject->getIOR();
873 tds = this->GetShapeFromIOR(ior);
884 //=======================================================================
885 // function : GetNameOfSelectedIObjects()
886 // purpose : Define the name geom++ or other name of mono or multi sel.
887 //=======================================================================
888 int GEOMBase::GetNameOfSelectedIObjects(SALOME_Selection* Sel, QString& aName)
890 int nbSel = Sel->IObjectCount();
892 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
893 aName = IObject->getName();
896 aName = tr("%1_objects").arg(nbSel);
902 //=================================================================================
903 // function : GetShapeTypeString()
904 // purpose : for a single shape
905 //=================================================================================
906 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
908 if(aShape.IsNull()) {
909 aTypeString = "aNullShape";
912 switch(aShape.ShapeType())
914 case TopAbs_COMPOUND:
916 aTypeString = strdup(tr("GEOM_COMPOUND"));
919 case TopAbs_COMPSOLID:
921 aTypeString = strdup(tr("GEOM_COMPOUNDSOLID")) ;
926 aTypeString = strdup(tr("GEOM_SOLID")) ;
931 aTypeString = strdup(tr("GEOM_SHELL")) ;
936 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
937 if(surf.GetType() == GeomAbs_Plane) {
938 aTypeString = strdup(tr("GEOM_PLANE"));
941 else if(surf.GetType() == GeomAbs_Cylinder) {
942 aTypeString = strdup(tr("GEOM_SURFCYLINDER"));
945 else if(surf.GetType() == GeomAbs_Sphere) {
946 aTypeString = strdup(tr("GEOM_SURFSPHERE"));
949 else if(surf.GetType() == GeomAbs_Torus) {
950 aTypeString = strdup(tr("GEOM_SURFTORUS"));
953 else if(surf.GetType() == GeomAbs_Cone) {
954 aTypeString = strdup(tr("GEOM_SURFCONE"));
958 aTypeString = strdup(tr("GEOM_FACE"));
964 aTypeString = strdup(tr("GEOM_WIRE"));
969 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
970 if(curv.GetType() == GeomAbs_Line) {
971 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
972 aTypeString = strdup(tr("GEOM_LINE"));
974 aTypeString = strdup(tr("GEOM_EDGE"));
977 else if(curv.GetType() == GeomAbs_Circle) {
979 aTypeString = strdup(tr("GEOM_CIRCLE"));
981 aTypeString = strdup(tr("GEOM_ARC"));
985 aTypeString = strdup(tr("GEOM_EDGE"));
991 aTypeString = strdup(tr("GEOM_VERTEX"));
996 aTypeString = strdup(tr("GEOM_SHAPE"));
1004 //=======================================================================
1005 // function : ConvertIORinGEOMAISShape()
1007 //=======================================================================
1008 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
1010 Handle(GEOM_AISShape) resultShape;
1012 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1013 for(int i = 0; i < nbSf; i++) {
1014 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1015 if(sf->getTypeView() == VIEW_OCC) {
1016 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
1017 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
1019 AIS_ListOfInteractive List;
1020 ic->DisplayedObjects(List);
1021 AIS_ListOfInteractive List1;
1022 ic->ObjectsInCollector(List1);
1025 AIS_ListIteratorOfListOfInteractive ite(List);
1027 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1028 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1030 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
1031 Standard_CString theIOR = GIO->getIOR();
1032 if(strcmp(IOR, theIOR) == 0) {
1033 if(onlyInActiveView) {
1034 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1056 //=======================================================================
1057 // function : ConvertIORinGEOMActor()
1059 //=======================================================================
1060 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
1062 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1063 for(int i = 0; i < nbSf; i++) {
1064 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1065 if(sf->getTypeView() == VIEW_VTK) {
1066 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1067 vtkActorCollection* theActors = Renderer->GetActors();
1068 theActors->InitTraversal();
1069 vtkActor *ac = theActors->GetNextActor();
1070 while(!(ac==NULL)) {
1071 if( ac->IsA("GEOM_Actor")) {
1072 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
1073 if(anActor->hasIO()) {
1074 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(anActor->getIO());
1075 Standard_CString theIOR = GIO->getIOR();
1076 if(strcmp(IOR, theIOR) == 0) {
1077 if(onlyInActiveView) {
1078 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1090 ac = theActors->GetNextActor();
1095 return GEOM_Actor::New();
1099 //=======================================================================
1100 // function : ConvertIOinGEOMAISShape()
1102 //=======================================================================
1103 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
1105 Handle(GEOM_AISShape) res;
1106 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1107 for(int i = 0; i < nbSf; i++) {
1108 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
1109 if(sf->getTypeView() == VIEW_OCC) {
1110 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
1111 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
1113 AIS_ListOfInteractive List;
1114 ic->DisplayedObjects(List);
1115 AIS_ListOfInteractive List1;
1116 ic->ObjectsInCollector(List1);
1119 AIS_ListIteratorOfListOfInteractive ite(List);
1121 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1122 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1124 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
1125 if(GIO->isSame(IO)) {
1126 if(onlyInActiveView) {
1127 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
1148 //=======================================================================
1149 // function : ConvertIOinGEOMShape()
1151 //=======================================================================
1152 GEOM::GEOM_Shape_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
1154 GEOM::GEOM_Shape_var aShape;
1158 if(IO->hasEntry()) {
1159 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1160 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
1161 SALOMEDS::GenericAttribute_var anAttr;
1162 SALOMEDS::AttributeIOR_var anIOR;
1163 if(!obj->_is_nil()) {
1164 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
1165 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1166 aShape = myGeom->GetIORFromString(anIOR->Value());
1167 if(!CORBA::is_nil(aShape))
1169 return aShape._retn();
1173 /* case Graphical Object */
1174 if(IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
1175 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IO);
1176 Standard_CString ior = GIObject->getIOR();
1178 aShape = myGeom->GetIORFromString(ior);
1179 if(!CORBA::is_nil(aShape))
1181 return aShape._retn();
1183 return aShape._retn();
1187 //=======================================================================
1188 // function : ConvertListOfIOInListOfIOR()
1190 //=======================================================================
1191 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::GEOM_Gen::ListOfIOR& listIOR)
1193 int nbSel = aList.Extent();
1194 listIOR.length(nbSel);
1196 SALOME_ListIteratorOfListIO It(aList);
1197 for(int i=0; It.More(); It.Next(), i++) {
1198 Handle(SALOME_InteractiveObject) IObject = It.Value();
1199 if(IObject->hasEntry()) {
1200 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1201 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
1202 SALOMEDS::GenericAttribute_var anAttr;
1203 SALOMEDS::AttributeIOR_var anIOR;
1204 if(!obj->_is_nil() && obj->FindAttribute(anAttr, "AttributeIOR")) {
1205 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1206 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
1207 CORBA::ORB_var& _orb = init.orb();
1208 CORBA::String_var theValue = anIOR->Value();
1209 CORBA::Object_var theObj = _orb->string_to_object(theValue);
1210 if(theObj->_is_a("IDL:GEOM/GEOM_Shape:1.0")) {
1211 listIOR[j] = strdup(theValue);
1216 else if(IObject->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject))) {
1217 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast(IObject);
1218 Standard_CString ior = GIObject->getIOR();
1219 listIOR[j] = strdup(ior);
1227 //================================================================================
1228 // function : SetDisplayedObjectList()
1230 //================================================================================
1231 // void GEOMBase::SetDisplayedObjectList()
1233 // if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
1236 // OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1237 // myGeomGUI->GetListDisplayedObject().Clear();
1239 // Handle (AIS_InteractiveContext) aContext = v3d->getAISContext();
1240 // aContext->DisplayedObjects(myGeomGUI->GetListDisplayedObject());
1244 //=====================================================================================
1245 // function : DisplaySimulationShape()
1246 // purpose : Displays 'this->mySimulationShape' a pure graphical shape from a TopoDS_Shape
1247 //=====================================================================================
1248 void GEOMBase::DisplaySimulationShape(const TopoDS_Shape& S)
1253 //NRI DEBUG : 14/02/2002
1254 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
1257 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1258 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1260 /* erase any previous */
1261 ic->Erase(mySimulationShape, Standard_True, Standard_False);
1262 ic->ClearPrs(mySimulationShape);
1263 mySimulationShape = new AIS_Shape(TopoDS_Shape());
1264 mySimulationShape->Set(S);
1265 mySimulationShape->SetColor(Quantity_NOC_VIOLET);
1266 ic->Deactivate(mySimulationShape);
1267 ic->Display(mySimulationShape, Standard_False);
1268 ic->UpdateCurrentViewer();
1270 catch(Standard_Failure) {
1271 MESSAGE("Exception catched in GEOMBase::DisplaySimulationShape ");
1273 mySimulationShape->UnsetColor();
1278 //==================================================================================
1279 // function : EraseSimulationShape()
1280 // purpose : Clears the display of 'mySimulationShape' a pure graphical shape
1281 //==================================================================================
1282 void GEOMBase::EraseSimulationShape()
1284 int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
1285 for(int i = 0; i < count; i++) {
1286 if(QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
1287 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
1288 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1289 ic->Erase(mySimulationShape, Standard_True, Standard_False);
1290 ic->ClearPrs(mySimulationShape);
1291 ic->UpdateCurrentViewer();
1297 //=================================================================================
1298 // function : CreateArrowForLinearEdge()
1299 // purpose : Create a cone topology to be used to display an arrow in the middle
1300 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
1301 //=================================================================================
1302 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
1304 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC || tds.ShapeType() != TopAbs_EDGE)
1307 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
1308 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
1309 Standard_Real Width, Height;
1310 view3d->Size(Width, Height);
1311 const Standard_Real aHeight = (Width + Height) / 50.0;
1314 Standard_Real first, last;
1315 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
1319 const Standard_Real param = (first+last) / 2.0;
1320 gp_Pnt middleParamPoint;
1322 curv->D1( param, middleParamPoint, V1);
1323 if(V1.Magnitude() < Precision::Confusion())
1326 /* Topology orientation not geom orientation */
1327 if(tds.Orientation() == TopAbs_REVERSED)
1330 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
1331 const Standard_Real radius1 = aHeight / 5.0;
1332 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
1333 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
1337 catch(Standard_Failure) {
1338 // OCC failures are hard to catch in GUI.
1339 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
1340 // in SALOME environment : compilation error !
1346 //=================================================================================
1347 // function : VertexToPoint()
1348 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
1349 //=================================================================================
1350 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
1352 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
1354 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
1359 //=================================================================================
1360 // function : GetBipointDxDyDz()
1362 //=================================================================================
1363 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
1365 dx = P2.X() - P1.X();
1366 dy = P2.Y() - P1.Y();
1367 dz = P2.Z() - P1.Z();
1372 //=================================================================================
1373 // function : LinearEdgeExtremities()
1374 // purpose : If S can be converted in a linear edge and if initial an final points
1375 // : distance is sufficient, returns true else returns false.
1376 // : Resulting points are respectively P1 and P2
1377 //=================================================================================
1378 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
1380 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
1382 BRepAdaptor_Curve curv(TopoDS::Edge(S));
1383 if(curv.GetType() != GeomAbs_Line)
1386 curv.D0(curv.FirstParameter(), P1);
1387 curv.D0(curv.LastParameter(), P2);
1389 if(P1.Distance(P2) <= Precision::Confusion())
1396 //=======================================================================
1397 // function : Parameter()
1398 // purpose : return a parameter (float) from a dialog box
1400 // avalue1 : is a float or integer used as a default value displayed
1401 // aTitle1 : is the title for aValue1
1402 // aTitle : is the main title
1403 // bottom : maximum value to be entered
1404 // top : minimum value to be entered
1405 // decimals : number of decimals
1406 //=======================================================================
1407 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
1409 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, QAD_Application::getDesktop(), aTitle, TRUE, 0, bottom, top, decimals);
1410 int r = Dialog->exec();
1412 if(r == QDialog::Accepted) {
1413 res = Standard_True;
1414 X = Dialog->getValue();
1417 res = Standard_False;
1423 //=======================================================================
1424 // function : SelectionByNameInDialogs()
1425 // purpose : Called when user has entered a name of object in a LineEdit.
1426 // : The selection is changed. Dialog box will receive the
1427 // : corresponding signal to manage this event.
1428 //=======================================================================
1429 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, SALOME_Selection* Sel)
1431 /* Find SObject with name in component GEOM */
1432 SALOMEDS::Study_var ST = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
1433 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
1434 listSO = ST->FindObjectByName(objectUserName, "GEOM");
1436 if(listSO->length() < 1) {
1437 const QString caption = tr("GEOM_WRN_WARNING");
1438 const QString text = tr("GEOM_NAME_INCORRECT");
1439 const QString button0 = tr("GEOM_BUT_OK");
1440 QMessageBox::warning(aWidget, caption, text, button0);
1443 /* More than one object with same name */
1444 if(listSO->length() > 1) {
1445 const QString caption = tr("GEOM_WRN_WARNING");
1446 const QString text = tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
1447 const QString button0 = tr("GEOM_BUT_OK") ;
1448 QMessageBox::warning(aWidget, caption, text, button0) ;
1452 SALOMEDS::SObject_var theObj = listSO[0];
1453 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
1454 Standard_CString anEntry = theObj->GetID();
1455 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(anEntry, "GEOM", strdup(objectUserName));
1457 /* Add as a selected object */
1458 /* Clear any previous selection : */
1459 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
1460 Sel->ClearIObjects();
1461 Sel->AddIObject(SI);
1466 //=======================================================================
1467 // function : DefineDlgPosition()
1468 // purpose : Define x and y the default position for a dialog box
1469 //=======================================================================
1470 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
1472 /* Here the position is on the bottom right corner - 10 */
1473 QAD_Desktop* PP = QAD_Application::getDesktop();
1474 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
1475 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
1480 //=====================================================================================
1482 //=====================================================================================
1485 bool CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
1486 const QString & theParent, const QString & theObject)
1487 {return GEOMBase::CustomPopup(parent, popup, theContext, theParent, theObject);}