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>
64 #include <Precision.hxx>
66 #include <vtkRenderer.h>
70 //=====================================================================================
71 // function : GetShapeFromIOR()
72 // purpose : exist also as static method !
73 //=====================================================================================
74 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
77 if(IOR.trimmed().isEmpty())
80 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
81 if(CORBA::is_nil(obj))
83 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
84 if (GeomObject->_is_nil())
87 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
92 //=====================================================================================
93 // function : GetIndex()
94 // purpose : Get the index of a sub shape in a main shape : index start at 1
95 //=====================================================================================
96 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
98 if(shape.IsNull() || subshape.IsNull())
101 TopTools_IndexedMapOfShape anIndices;
102 TopExp::MapShapes(shape, anIndices);
103 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
109 //=======================================================================
110 // function : GetTopoFromSelection()
111 // purpose : Define tds from a single selection and retuen true
112 //=======================================================================
113 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
115 if(aList.Extent() != 1)
118 Handle(SALOME_InteractiveObject) IO = aList.First();
121 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
122 if ( !appStudy ) return false;
123 _PTR(Study) aStudy = appStudy->studyDS();
125 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
126 _PTR(GenericAttribute) anAttr;
128 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
129 _PTR(AttributeIOR) anIOR ( anAttr );
130 tds = GetShapeFromIOR(anIOR->Value().c_str());
142 //=======================================================================
143 // function : GetNameOfSelectedIObjects()
144 // purpose : Define the name geom++ or other name of mono or multi sel.
145 //=======================================================================
146 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
148 const bool theShapesOnly )
150 if ( !theShapesOnly )
152 int nbSel = aList.Extent();
155 Handle(SALOME_InteractiveObject) anIObj = aList.First();
156 if(anIObj->hasEntry()) {
157 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
158 if ( !appStudy ) return nbSel;
159 _PTR(Study) aStudy = appStudy->studyDS();
161 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
163 _PTR(GenericAttribute) anAttr;
165 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
167 _PTR(AttributeName) aNameAttr ( anAttr );
168 theName = aNameAttr->Value().c_str();
173 theName = QObject::tr("%1_objects").arg(nbSel);
179 GEOM::ListOfGO anObjs;
180 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
181 if ( anObjs.length() == 1 ) {
182 theName = GetName( anObjs[ 0 ] );
185 theName = QString( "%1_objects" ).arg( anObjs.length() );
187 return anObjs.length();
192 //=================================================================================
193 // function : GetShapeTypeString()
194 // purpose : for a single shape
195 //=================================================================================
196 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
198 if(aShape.IsNull()) {
199 aTypeString = "aNullShape";
202 switch(aShape.ShapeType())
204 case TopAbs_COMPOUND:
206 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND").toLatin1().constData());
209 case TopAbs_COMPSOLID:
211 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID").toLatin1().constData()) ;
216 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID").toLatin1().constData()) ;
221 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL").toLatin1().constData()) ;
226 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
227 if(surf.GetType() == GeomAbs_Plane) {
228 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE").toLatin1().constData());
231 else if(surf.GetType() == GeomAbs_Cylinder) {
232 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER").toLatin1().constData());
235 else if(surf.GetType() == GeomAbs_Sphere) {
236 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE").toLatin1().constData());
239 else if(surf.GetType() == GeomAbs_Torus) {
240 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS").toLatin1().constData());
243 else if(surf.GetType() == GeomAbs_Cone) {
244 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE").toLatin1().constData());
248 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE").toLatin1().constData());
254 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE").toLatin1().constData());
259 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
260 if(curv.GetType() == GeomAbs_Line) {
261 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
262 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE").toLatin1().constData());
264 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
267 else if(curv.GetType() == GeomAbs_Circle) {
269 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE").toLatin1().constData());
271 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC").toLatin1().constData());
275 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
281 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX").toLatin1().constData());
286 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE").toLatin1().constData());
294 //=======================================================================
295 // function : ConvertIORinGEOMAISShape()
297 //=======================================================================
298 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
300 Handle(GEOM_AISShape) resultShape;
303 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
304 if ( !appStudy ) return resultShape;
305 _PTR(Study) aStudy = appStudy->studyDS();
307 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
311 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
313 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
314 while ( it.hasNext() ) {
315 SUIT_ViewWindow* aVW = it.next();
316 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
317 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
319 AIS_ListOfInteractive List;
320 ic->DisplayedObjects(List);
321 AIS_ListOfInteractive List1;
322 ic->ObjectsInCollector(List1);
325 AIS_ListIteratorOfListOfInteractive ite(List);
327 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
328 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
330 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
331 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
332 if(!onlyInActiveView ||
333 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
349 //=======================================================================
350 // function : ConvertIORinGEOMActor()
352 //=======================================================================
353 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
357 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
358 if ( !appStudy ) return GEOM_Actor::New();
359 _PTR(Study) aStudy = appStudy->studyDS();
361 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
363 return GEOM_Actor::New();
365 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
367 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
368 while ( it.hasNext() ) {
369 SUIT_ViewWindow* aVW = it.next();
370 if (aVW && aVW->getViewManager()->getType() == SVTK_Viewer::Type()) {
371 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( aVW );
372 if( !aVTKViewWindow )
374 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
375 vtkActorCollection* theActors = Renderer->GetActors();
376 theActors->InitTraversal();
377 vtkActor *ac = theActors->GetNextActor();
379 if( ac->IsA("GEOM_Actor")) {
380 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
381 if(anActor->hasIO()) {
382 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
383 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
384 if(!onlyInActiveView ||
385 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
392 ac = theActors->GetNextActor();
397 return GEOM_Actor::New();
400 //=======================================================================
401 // function : GetAIS()
403 //=======================================================================
404 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
405 const bool isOnlyInActiveView )
407 if ( theIO.IsNull() || !theIO->hasEntry() )
408 return Handle(AIS_InteractiveObject)();
410 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
412 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
413 while ( it.hasNext() ) {
414 SUIT_ViewWindow* aVW = it.next();
415 if (!aVW || aVW->getViewManager()->getType() != OCCViewer_Viewer::Type())
417 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
419 AIS_ListOfInteractive aList;
420 anIC->DisplayedObjects( aList );
421 anIC->ObjectsInCollector( aList );
423 AIS_ListIteratorOfListOfInteractive anIter( aList );
424 for ( ; anIter.More(); anIter.Next() )
426 Handle(SALOME_InteractiveObject) anObj =
427 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
429 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
431 if( isOnlyInActiveView )
433 if ( aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
434 return anIter.Value();
437 return anIter.Value();
442 return Handle(AIS_InteractiveObject)();
446 //=======================================================================
447 // function : ConvertIOinGEOMAISShape()
449 //=======================================================================
450 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
452 Handle(GEOM_AISShape) res;
454 if ( !IO->hasEntry() )
460 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
462 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
463 while ( it.hasNext() ) {
464 SUIT_ViewWindow* aVW = it.next();
465 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
466 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
468 AIS_ListOfInteractive List;
469 ic->DisplayedObjects(List);
470 AIS_ListOfInteractive List1;
471 ic->ObjectsInCollector(List1);
474 AIS_ListIteratorOfListOfInteractive ite(List);
477 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
479 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
482 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
486 if(aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
509 //=======================================================================
510 // function : ConvertIOinGEOMShape()
512 //=======================================================================
513 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
515 GEOM::GEOM_Object_var aShape;
520 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
521 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
522 _PTR(Study) aStudy = appStudy->studyDS();
524 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
525 _PTR(GenericAttribute) anAttr;
527 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
528 _PTR(AttributeIOR) anIOR ( anAttr );
529 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
530 if(!CORBA::is_nil(aShape))
532 return aShape._retn();
536 return GEOM::GEOM_Object::_nil();
540 //=======================================================================
541 // function : ConvertListOfIOInListOfIOR()
543 //=======================================================================
544 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
546 int nbSel = aList.Extent();
547 listIOR.length(nbSel);
549 SALOME_ListIteratorOfListIO It(aList);
550 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
551 ( SUIT_Session::session()->activeApplication()->activeStudy() );
552 if ( !appStudy ) return;
553 _PTR(Study) aStudy = appStudy->studyDS();
555 for (int i=0; It.More(); It.Next(), i++) {
556 Handle(SALOME_InteractiveObject) IObject = It.Value();
557 if (IObject->hasEntry()) {
558 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
559 _PTR(GenericAttribute) anAttr;
560 if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
561 _PTR(AttributeIOR) anIOR (anAttr);
562 //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
563 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
564 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
565 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
566 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
576 //=======================================================================
577 // function : ConvertIOinGEOMObject()
579 //=======================================================================
580 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
581 Standard_Boolean& theResult )
583 theResult = Standard_False;
584 GEOM::GEOM_Object_var aReturnObject;
585 if ( !theIO.IsNull() )
587 const char* anEntry = theIO->getEntry();
589 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
590 ( SUIT_Session::session()->activeApplication()->activeStudy() );
591 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
592 _PTR(Study) aStudy = appStudy->studyDS();
594 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
598 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
599 theResult = !CORBA::is_nil( aReturnObject );
602 return aReturnObject._retn();
606 //=======================================================================
607 // function : ConvertListOfIOInListOfGO()
609 //=======================================================================
610 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
611 GEOM::ListOfGO& theListGO,
612 const bool theShapesOnly )
614 int nbSel = theList.Extent();
615 theListGO.length( nbSel );
616 SALOME_ListIteratorOfListIO anIter( theList );
618 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
619 if ( !appStudy ) return;
620 _PTR(Study) aStudy = appStudy->studyDS();
623 for ( int i=0; anIter.More(); anIter.Next(), i++ )
625 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
626 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
630 GEOM::GEOM_Object_var aGeomObj =
631 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
632 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
633 theListGO[ j++ ] = aGeomObj;
637 theListGO.length( j );
640 //=================================================================================
641 // function : CreateArrowForLinearEdge()
642 // purpose : Create a cone topology to be used to display an arrow in the middle
643 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
644 //=================================================================================
645 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
647 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
648 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
651 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
652 Handle( V3d_View) view3d = vp3d->getView();
653 Standard_Real Width, Height;
654 view3d->Size(Width, Height);
655 const Standard_Real aHeight = (Width + Height) / 50.0;
658 Standard_Real first, last;
659 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
663 const Standard_Real param = (first+last) / 2.0;
664 gp_Pnt middleParamPoint;
666 curv->D1( param, middleParamPoint, V1);
667 if(V1.Magnitude() < Precision::Confusion())
670 /* Topology orientation not geom orientation */
671 if(tds.Orientation() == TopAbs_REVERSED)
674 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
675 const Standard_Real radius1 = aHeight / 5.0;
676 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
677 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
681 catch(Standard_Failure) {
682 // OCC failures are hard to catch in GUI.
683 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
684 // in SALOME environment : compilation error !
690 //=================================================================================
691 // function : VertexToPoint()
692 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
693 //=================================================================================
694 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
696 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
698 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
703 //=================================================================================
704 // function : GetBipointDxDyDz()
706 //=================================================================================
707 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
709 dx = P2.X() - P1.X();
710 dy = P2.Y() - P1.Y();
711 dz = P2.Z() - P1.Z();
716 //=================================================================================
717 // function : LinearEdgeExtremities()
718 // purpose : If S can be converted in a linear edge and if initial an final points
719 // : distance is sufficient, returns true else returns false.
720 // : Resulting points are respectively P1 and P2
721 //=================================================================================
722 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
724 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
726 BRepAdaptor_Curve curv(TopoDS::Edge(S));
727 if(curv.GetType() != GeomAbs_Line)
730 curv.D0(curv.FirstParameter(), P1);
731 curv.D0(curv.LastParameter(), P2);
733 if(P1.Distance(P2) <= Precision::Confusion())
740 //=======================================================================
741 // function : SelectionByNameInDialogs()
742 // purpose : Called when user has entered a name of object in a LineEdit.
743 // : The selection is changed. Dialog box will receive the
744 // : corresponding signal to manage this event.
745 //=======================================================================
746 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
748 /* Find SObject with name in component GEOM */
749 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
750 if ( !appStudy ) return false;
751 _PTR(Study) ST = appStudy->studyDS();
753 std::vector<_PTR(SObject)> listSO;
754 listSO = ST->FindObjectByName(objectUserName.toStdString(), "GEOM");
756 if(listSO.size() < 1) {
757 const QString caption = QObject::tr("GEOM_WRN_WARNING");
758 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
759 const QString button0 = QObject::tr("GEOM_BUT_OK");
760 SUIT_MessageBox::critical(aWidget, caption, text, button0);
763 /* More than one object with same name */
764 if(listSO.size() > 1) {
765 const QString caption = QObject::tr("GEOM_WRN_WARNING");
766 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
767 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
768 SUIT_MessageBox::critical(aWidget, caption, text, button0) ;
773 _PTR(SObject) theObj ( listSO[0] );
774 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
775 char* aCopyobjectUserName = CORBA::string_dup(objectUserName.toLatin1().constData());
776 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
777 delete(aCopyobjectUserName);
779 /* Add as a selected object */
780 /* Clear any previous selection : */
781 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
782 // Sel->ClearIObjects(); //mzn
783 // Sel->AddIObject(SI); //mzn
788 //=======================================================================
789 // function : DefineDlgPosition()
790 // purpose : Define x and y the default position for a dialog box
791 //=======================================================================
792 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
794 /* Here the position is on the bottom right corner - 10 */
795 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
796 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
797 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
802 //=======================================================================
803 // function : GetDefaultName()
804 // purpose : Generates default names
805 //=======================================================================
806 QString GEOMBase::GetDefaultName(const QString& theOperation)
810 // collect all object names of GEOM component
811 SalomeApp_Study* appStudy =
812 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
813 if ( !appStudy ) return aName;
814 _PTR(Study) aStudy = appStudy->studyDS();
816 std::set<std::string> aSet;
817 _PTR(SComponent) aGeomCompo (aStudy->FindComponent("GEOM"));
819 _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeomCompo));
821 for (it->InitEx(true); it->More(); it->Next()) {
823 aSet.insert(obj->GetName());
827 // build a unique name
829 bool isUnique = false;
831 aName = theOperation + "_" + QString::number(++aNumber);
832 isUnique = (aSet.count(aName.toStdString()) == 0);
839 //=======================================================================
840 // function : ShowErrorMessage()
841 // purpose : Shows message box with error code and comment
842 //=======================================================================
843 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
845 QString anErrorCode(theErrorCode);
846 QString aComment(theComment);
849 if (!anErrorCode.isEmpty())
850 aText.append("\n" + QObject::tr(anErrorCode.toLatin1().constData()));
851 if (!aComment.isEmpty())
852 aText.append("\n" + QString(theComment));
854 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
855 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
859 //=======================================================================
860 // function : GetObjectFromIOR()
861 // purpose : returns a GEOM_Object by given IOR (string)
862 //=======================================================================
863 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
865 GEOM::GEOM_Object_var anObject;
866 if ( theIOR == NULL || strlen( theIOR ) == 0 )
867 return anObject._retn(); // returning nil object
869 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
870 return anObject._retn();
873 //=======================================================================
874 // function : GetIORFromObject()
875 // purpose : returns IOR of a given GEOM_Object
876 //=======================================================================
877 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
879 if ( CORBA::is_nil( theObject ) )
882 return SalomeApp_Application::orb()->object_to_string( theObject );
885 //=======================================================================
886 // function : GetShape()
887 // purpose : returns a TopoDS_Shape stored in GEOM_Object
888 //=======================================================================
889 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
891 if ( !CORBA::is_nil( theObject ) )
893 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
894 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
896 theShape = aTopoDSShape;
903 //=======================================================================
904 // function : GetName()
905 // purpose : Get name of object
906 //=======================================================================
907 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
909 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
913 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
914 if ( strcmp(anIOR.in(), "") != 0 )
916 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( std::string( anIOR ) ) );
918 _PTR(GenericAttribute) anAttr;
920 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
922 _PTR(AttributeName) aNameAttr ( anAttr );
923 return QString( aNameAttr->Value().c_str() );
931 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
933 return !theObj->_is_nil() && theObj->IsShape();