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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMBase.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
28 #include <GeometryGUI.h>
29 #include <GEOM_Client.hxx>
32 #include <GEOM_Actor.h>
33 #include <SVTK_ViewModel.h>
34 #include <SVTK_ViewWindow.h>
35 #include <OCCViewer_ViewPort3d.h>
36 #include <OCCViewer_ViewModel.h>
37 #include <OCCViewer_ViewWindow.h>
39 #include <SALOME_ListIO.hxx>
40 #include <SALOME_ListIteratorOfListIO.hxx>
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_ViewManager.h>
45 #include <SUIT_ViewWindow.h>
46 #include <SUIT_MessageBox.h>
47 #include <SalomeApp_Application.h>
48 #include <SalomeApp_Study.h>
50 // // Open CASCADE Includes
51 #include <BRep_Tool.hxx>
52 #include <BRepAdaptor_Curve.hxx>
53 #include <BRepAdaptor_Surface.hxx>
54 #include <BRepPrimAPI_MakeCone.hxx>
56 #include <AIS_ListIteratorOfListOfInteractive.hxx>
57 #include <AIS_ListOfInteractive.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <Precision.hxx>
65 #include <vtkRenderer.h>
72 //=====================================================================================
73 // function : GetShapeFromIOR()
74 // purpose : exist also as static method !
75 //=====================================================================================
76 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
79 if(IOR.trimmed().isEmpty())
82 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
83 if(CORBA::is_nil(obj))
85 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
86 if (GeomObject->_is_nil())
89 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
94 //=====================================================================================
95 // function : GetIndex()
96 // purpose : Get the index of a sub shape in a main shape : index start at 1
97 //=====================================================================================
98 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
100 if(shape.IsNull() || subshape.IsNull())
103 TopTools_IndexedMapOfShape anIndices;
104 TopExp::MapShapes(shape, anIndices);
105 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
111 //=======================================================================
112 // function : GetTopoFromSelection()
113 // purpose : Define tds from a single selection and retuen true
114 //=======================================================================
115 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
117 if(aList.Extent() != 1)
120 Handle(SALOME_InteractiveObject) IO = aList.First();
123 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
124 if ( !appStudy ) return false;
125 _PTR(Study) aStudy = appStudy->studyDS();
127 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
128 _PTR(GenericAttribute) anAttr;
130 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
131 _PTR(AttributeIOR) anIOR ( anAttr );
132 tds = GetShapeFromIOR(anIOR->Value().c_str());
144 //=======================================================================
145 // function : GetNameOfSelectedIObjects()
146 // purpose : Define the name geom++ or other name of mono or multi sel.
147 //=======================================================================
148 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
150 const bool theShapesOnly )
152 if ( !theShapesOnly )
154 int nbSel = aList.Extent();
157 Handle(SALOME_InteractiveObject) anIObj = aList.First();
158 if(anIObj->hasEntry()) {
159 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
160 if ( !appStudy ) return nbSel;
161 _PTR(Study) aStudy = appStudy->studyDS();
163 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
165 _PTR(GenericAttribute) anAttr;
167 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
169 _PTR(AttributeName) aNameAttr ( anAttr );
170 theName = aNameAttr->Value().c_str();
175 theName = QObject::tr("%1_objects").arg(nbSel);
181 GEOM::ListOfGO anObjs;
182 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
183 if ( anObjs.length() == 1 ) {
184 theName = GetName( anObjs[ 0 ] );
187 theName = QString( "%1_objects" ).arg( anObjs.length() );
189 return anObjs.length();
194 //=================================================================================
195 // function : GetShapeTypeString()
196 // purpose : for a single shape
197 //=================================================================================
198 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
200 if(aShape.IsNull()) {
201 aTypeString = "aNullShape";
204 switch(aShape.ShapeType())
206 case TopAbs_COMPOUND:
208 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND").toLatin1().constData());
211 case TopAbs_COMPSOLID:
213 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID").toLatin1().constData()) ;
218 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID").toLatin1().constData()) ;
223 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL").toLatin1().constData()) ;
228 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
229 if(surf.GetType() == GeomAbs_Plane) {
230 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE").toLatin1().constData());
233 else if(surf.GetType() == GeomAbs_Cylinder) {
234 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER").toLatin1().constData());
237 else if(surf.GetType() == GeomAbs_Sphere) {
238 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE").toLatin1().constData());
241 else if(surf.GetType() == GeomAbs_Torus) {
242 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS").toLatin1().constData());
245 else if(surf.GetType() == GeomAbs_Cone) {
246 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE").toLatin1().constData());
250 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE").toLatin1().constData());
256 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE").toLatin1().constData());
261 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
262 if(curv.GetType() == GeomAbs_Line) {
263 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
264 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE").toLatin1().constData());
266 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
269 else if(curv.GetType() == GeomAbs_Circle) {
271 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE").toLatin1().constData());
273 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC").toLatin1().constData());
277 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
283 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX").toLatin1().constData());
288 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE").toLatin1().constData());
296 //=======================================================================
297 // function : ConvertIORinGEOMAISShape()
299 //=======================================================================
300 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
302 Handle(GEOM_AISShape) resultShape;
305 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
306 if ( !appStudy ) return resultShape;
307 _PTR(Study) aStudy = appStudy->studyDS();
309 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
313 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
315 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
316 while ( it.hasNext() ) {
317 SUIT_ViewWindow* aVW = it.next();
318 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
319 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
321 AIS_ListOfInteractive List;
322 ic->DisplayedObjects(List);
323 AIS_ListOfInteractive List1;
324 ic->ObjectsInCollector(List1);
327 AIS_ListIteratorOfListOfInteractive ite(List);
329 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
330 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
332 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
333 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
334 if(!onlyInActiveView ||
335 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
351 //=======================================================================
352 // function : ConvertIORinGEOMActor()
354 //=======================================================================
355 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
359 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
360 if ( !appStudy ) return GEOM_Actor::New();
361 _PTR(Study) aStudy = appStudy->studyDS();
363 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
365 return GEOM_Actor::New();
367 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
369 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
370 while ( it.hasNext() ) {
371 SUIT_ViewWindow* aVW = it.next();
372 if (aVW && aVW->getViewManager()->getType() == SVTK_Viewer::Type()) {
373 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( aVW );
374 if( !aVTKViewWindow )
376 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
377 vtkActorCollection* theActors = Renderer->GetActors();
378 theActors->InitTraversal();
379 vtkActor *ac = theActors->GetNextActor();
381 if( ac->IsA("GEOM_Actor")) {
382 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
383 if(anActor->hasIO()) {
384 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
385 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
386 if(!onlyInActiveView ||
387 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
394 ac = theActors->GetNextActor();
399 return GEOM_Actor::New();
402 //=======================================================================
403 // function : GetAIS()
405 //=======================================================================
406 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
407 const bool isOnlyInActiveView )
409 if ( theIO.IsNull() || !theIO->hasEntry() )
410 return Handle(AIS_InteractiveObject)();
412 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
414 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
415 while ( it.hasNext() ) {
416 SUIT_ViewWindow* aVW = it.next();
417 if (!aVW || aVW->getViewManager()->getType() != OCCViewer_Viewer::Type())
419 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
421 AIS_ListOfInteractive aList;
422 anIC->DisplayedObjects( aList );
423 anIC->ObjectsInCollector( aList );
425 AIS_ListIteratorOfListOfInteractive anIter( aList );
426 for ( ; anIter.More(); anIter.Next() )
428 Handle(SALOME_InteractiveObject) anObj =
429 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
431 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
433 if( isOnlyInActiveView )
435 if ( aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
436 return anIter.Value();
439 return anIter.Value();
444 return Handle(AIS_InteractiveObject)();
448 //=======================================================================
449 // function : ConvertIOinGEOMAISShape()
451 //=======================================================================
452 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
454 Handle(GEOM_AISShape) res;
456 if ( !IO->hasEntry() )
462 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
464 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
465 while ( it.hasNext() ) {
466 SUIT_ViewWindow* aVW = it.next();
467 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
468 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
470 AIS_ListOfInteractive List;
471 ic->DisplayedObjects(List);
472 AIS_ListOfInteractive List1;
473 ic->ObjectsInCollector(List1);
476 AIS_ListIteratorOfListOfInteractive ite(List);
479 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
481 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
484 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
488 if(aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
511 //=======================================================================
512 // function : ConvertIOinGEOMShape()
514 //=======================================================================
515 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
517 GEOM::GEOM_Object_var aShape;
522 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
523 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
524 _PTR(Study) aStudy = appStudy->studyDS();
526 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
527 _PTR(GenericAttribute) anAttr;
529 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
530 _PTR(AttributeIOR) anIOR ( anAttr );
531 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
532 if(!CORBA::is_nil(aShape))
534 return aShape._retn();
538 return GEOM::GEOM_Object::_nil();
542 //=======================================================================
543 // function : ConvertListOfIOInListOfIOR()
545 //=======================================================================
546 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
548 int nbSel = aList.Extent();
549 listIOR.length(nbSel);
551 SALOME_ListIteratorOfListIO It(aList);
552 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
553 ( SUIT_Session::session()->activeApplication()->activeStudy() );
554 if ( !appStudy ) return;
555 _PTR(Study) aStudy = appStudy->studyDS();
557 for (int i=0; It.More(); It.Next(), i++) {
558 Handle(SALOME_InteractiveObject) IObject = It.Value();
559 if (IObject->hasEntry()) {
560 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
561 _PTR(GenericAttribute) anAttr;
562 if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
563 _PTR(AttributeIOR) anIOR (anAttr);
564 //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
565 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
566 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
567 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
568 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
578 //=======================================================================
579 // function : ConvertIOinGEOMObject()
581 //=======================================================================
582 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
583 Standard_Boolean& theResult )
585 theResult = Standard_False;
586 GEOM::GEOM_Object_var aReturnObject;
587 if ( !theIO.IsNull() )
589 const char* anEntry = theIO->getEntry();
591 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
592 ( SUIT_Session::session()->activeApplication()->activeStudy() );
593 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
594 _PTR(Study) aStudy = appStudy->studyDS();
596 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
600 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
601 theResult = !CORBA::is_nil( aReturnObject );
604 return aReturnObject._retn();
608 //=======================================================================
609 // function : ConvertListOfIOInListOfGO()
611 //=======================================================================
612 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
613 GEOM::ListOfGO& theListGO,
614 const bool theShapesOnly )
616 int nbSel = theList.Extent();
617 theListGO.length( nbSel );
618 SALOME_ListIteratorOfListIO anIter( theList );
620 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
621 if ( !appStudy ) return;
622 _PTR(Study) aStudy = appStudy->studyDS();
625 for ( int i=0; anIter.More(); anIter.Next(), i++ )
627 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
628 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
632 GEOM::GEOM_Object_var aGeomObj =
633 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
634 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
635 theListGO[ j++ ] = aGeomObj;
639 theListGO.length( j );
642 //=================================================================================
643 // function : CreateArrowForLinearEdge()
644 // purpose : Create a cone topology to be used to display an arrow in the middle
645 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
646 //=================================================================================
647 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
649 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
650 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
653 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
654 Handle( V3d_View) view3d = vp3d->getView();
655 Standard_Real Width, Height;
656 view3d->Size(Width, Height);
657 const Standard_Real aHeight = (Width + Height) / 50.0;
660 Standard_Real first, last;
661 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
665 const Standard_Real param = (first+last) / 2.0;
666 gp_Pnt middleParamPoint;
668 curv->D1( param, middleParamPoint, V1);
669 if(V1.Magnitude() < Precision::Confusion())
672 /* Topology orientation not geom orientation */
673 if(tds.Orientation() == TopAbs_REVERSED)
676 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
677 const Standard_Real radius1 = aHeight / 5.0;
678 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
679 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
683 catch(Standard_Failure) {
684 // OCC failures are hard to catch in GUI.
685 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
686 // in SALOME environment : compilation error !
692 //=================================================================================
693 // function : VertexToPoint()
694 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
695 //=================================================================================
696 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
698 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
700 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
705 //=================================================================================
706 // function : GetBipointDxDyDz()
708 //=================================================================================
709 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
711 dx = P2.X() - P1.X();
712 dy = P2.Y() - P1.Y();
713 dz = P2.Z() - P1.Z();
718 //=================================================================================
719 // function : LinearEdgeExtremities()
720 // purpose : If S can be converted in a linear edge and if initial an final points
721 // : distance is sufficient, returns true else returns false.
722 // : Resulting points are respectively P1 and P2
723 //=================================================================================
724 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
726 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
728 BRepAdaptor_Curve curv(TopoDS::Edge(S));
729 if(curv.GetType() != GeomAbs_Line)
732 curv.D0(curv.FirstParameter(), P1);
733 curv.D0(curv.LastParameter(), P2);
735 if(P1.Distance(P2) <= Precision::Confusion())
742 //=======================================================================
743 // function : SelectionByNameInDialogs()
744 // purpose : Called when user has entered a name of object in a LineEdit.
745 // : The selection is changed. Dialog box will receive the
746 // : corresponding signal to manage this event.
747 //=======================================================================
748 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
750 /* Find SObject with name in component GEOM */
751 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
752 if ( !appStudy ) return false;
753 _PTR(Study) ST = appStudy->studyDS();
755 std::vector<_PTR(SObject)> listSO;
756 listSO = ST->FindObjectByName(objectUserName.toStdString(), "GEOM");
758 if(listSO.size() < 1) {
759 const QString caption = QObject::tr("GEOM_WRN_WARNING");
760 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
761 const QString button0 = QObject::tr("GEOM_BUT_OK");
762 SUIT_MessageBox::critical(aWidget, caption, text, button0);
765 /* More than one object with same name */
766 if(listSO.size() > 1) {
767 const QString caption = QObject::tr("GEOM_WRN_WARNING");
768 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
769 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
770 SUIT_MessageBox::critical(aWidget, caption, text, button0) ;
775 _PTR(SObject) theObj ( listSO[0] );
776 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
777 char* aCopyobjectUserName = CORBA::string_dup(objectUserName.toLatin1().constData());
778 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
779 delete(aCopyobjectUserName);
781 /* Add as a selected object */
782 /* Clear any previous selection : */
783 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
784 // Sel->ClearIObjects(); //mzn
785 // Sel->AddIObject(SI); //mzn
790 //=======================================================================
791 // function : DefineDlgPosition()
792 // purpose : Define x and y the default position for a dialog box
793 //=======================================================================
794 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
796 /* Here the position is on the bottom right corner - 10 */
797 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
798 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
799 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
804 //=======================================================================
805 // function : GetDefaultName()
806 // purpose : Generates default names
807 //=======================================================================
808 QString GEOMBase::GetDefaultName(const QString& theOperation)
812 // collect all object names of GEOM component
813 SalomeApp_Study* appStudy =
814 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
815 if ( !appStudy ) return aName;
816 _PTR(Study) aStudy = appStudy->studyDS();
818 std::set<std::string> aSet;
819 _PTR(SComponent) aGeomCompo (aStudy->FindComponent("GEOM"));
821 _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeomCompo));
823 for (it->InitEx(true); it->More(); it->Next()) {
825 aSet.insert(obj->GetName());
829 // build a unique name
831 bool isUnique = false;
833 aName = theOperation + "_" + QString::number(++aNumber);
834 isUnique = (aSet.count(aName.toStdString()) == 0);
841 //=======================================================================
842 // function : ShowErrorMessage()
843 // purpose : Shows message box with error code and comment
844 //=======================================================================
845 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
847 QString anErrorCode(theErrorCode);
848 QString aComment(theComment);
851 if (!anErrorCode.isEmpty())
852 aText.append("\n" + QObject::tr(anErrorCode.toLatin1().constData()));
853 if (!aComment.isEmpty())
854 aText.append("\n" + QString(theComment));
856 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
857 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
861 //=======================================================================
862 // function : GetObjectFromIOR()
863 // purpose : returns a GEOM_Object by given IOR (string)
864 //=======================================================================
865 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
867 GEOM::GEOM_Object_var anObject;
868 if ( theIOR == NULL || strlen( theIOR ) == 0 )
869 return anObject._retn(); // returning nil object
871 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
872 return anObject._retn();
875 //=======================================================================
876 // function : GetIORFromObject()
877 // purpose : returns IOR of a given GEOM_Object
878 //=======================================================================
879 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
881 if ( CORBA::is_nil( theObject ) )
884 return SalomeApp_Application::orb()->object_to_string( theObject );
887 //=======================================================================
888 // function : GetShape()
889 // purpose : returns a TopoDS_Shape stored in GEOM_Object
890 //=======================================================================
891 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
893 if ( !CORBA::is_nil( theObject ) )
895 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
896 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
898 theShape = aTopoDSShape;
905 //=======================================================================
906 // function : GetName()
907 // purpose : Get name of object
908 //=======================================================================
909 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
911 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
915 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
916 if ( strcmp(anIOR.in(), "") != 0 )
918 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( string( anIOR ) ) );
920 _PTR(GenericAttribute) anAttr;
922 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
924 _PTR(AttributeName) aNameAttr ( anAttr );
925 return QString( aNameAttr->Value().c_str() );
933 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
935 return !theObj->_is_nil() && theObj->IsShape();