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
30 #include "GeometryGUI.h"
31 #include "GEOMBase_aParameterDlg.h"
33 #include "GEOM_Client.hxx"
36 #include "Utils_ORB_INIT.hxx"
37 #include "Utils_SINGLETON.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
41 #include "GEOM_AssemblyBuilder.h"
42 #include "GEOM_Actor.h"
43 #include "VTKViewer_RenderWindowInteractor.h"
44 #include "VTKViewer_ViewModel.h"
45 #include "VTKViewer_ViewWindow.h"
46 #include "OCCViewer_ViewPort3d.h"
47 #include "OCCViewer_ViewModel.h"
48 #include "OCCViewer_ViewWindow.h"
50 #include "SALOME_ListIO.hxx"
51 #include "SALOME_ListIteratorOfListIO.hxx"
52 #include "GEOM_AISTrihedron.hxx"
54 #include "SUIT_Session.h"
55 #include "SUIT_ViewWindow.h"
56 #include "SUIT_MessageBox.h"
57 #include "SalomeApp_Application.h"
58 #include "SalomeApp_Study.h"
60 // // Open CASCADE Includes
61 #include <BRep_Tool.hxx>
62 #include <BRepAdaptor_Curve.hxx>
63 #include <BRepAdaptor_Surface.hxx>
64 #include <BRepPrimAPI_MakeCone.hxx>
66 #include <Geom_Circle.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
68 #include <AIS_ListOfInteractive.hxx>
72 #include <TopExp_Explorer.hxx>
73 #include <TopoDS_Iterator.hxx>
74 #include <TopoDS_Compound.hxx>
75 #include <TopTools_MapOfShape.hxx>
76 #include <TopTools_ListIteratorOfListOfShape.hxx>
77 #include <TopTools_IndexedMapOfShape.hxx>
79 #include <Precision.hxx>
81 #include <vtkRenderer.h>
82 #include <qvaluelist.h>
83 #include <qstringlist.h>
85 #include "GEOMImpl_Types.hxx"
89 #include "SALOMEDSClient.hxx"
90 #include "SALOMEDS_SObject.hxx"
91 #include "SALOMEDS_Study.hxx"
94 //=======================================================================
95 // function : GEOMBase()
96 // purpose : Constructor
97 //=======================================================================
103 //=======================================================================
104 // function : ~GEOMBase()
105 // purpose : Destructor
106 //=======================================================================
107 GEOMBase::~GEOMBase()
111 //=====================================================================================
112 // function : GetShapeFromIOR()
113 // purpose : exist also as static method !
114 //=====================================================================================
115 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
118 if(IOR.stripWhiteSpace().isEmpty())
121 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object((char*)(IOR.latin1()));
122 if(CORBA::is_nil(obj))
124 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
125 if (GeomObject->_is_nil())
128 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
133 //=====================================================================================
134 // function : GetIndex()
135 // purpose : Get the index of a sub shape in a main shape : index start at 1
136 //=====================================================================================
137 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
139 if(shape.IsNull() || subshape.IsNull())
142 TopTools_IndexedMapOfShape anIndices;
143 TopExp::MapShapes(shape, anIndices);
144 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
150 //=======================================================================
151 // function : GetTopoFromSelection()
152 // purpose : Define tds from a single selection and retuen true
153 //=======================================================================
154 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
156 if(aList.Extent() != 1)
159 Handle(SALOME_InteractiveObject) IO = aList.First();
162 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
163 if ( !appStudy ) return false;
164 _PTR(Study) aStudy = appStudy->studyDS();
166 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
167 _PTR(GenericAttribute) anAttr;
169 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
170 _PTR(AttributeIOR) anIOR ( anAttr );
171 tds = GetShapeFromIOR(anIOR->Value().c_str());
183 //=======================================================================
184 // function : GetNameOfSelectedIObjects()
185 // purpose : Define the name geom++ or other name of mono or multi sel.
186 //=======================================================================
187 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
189 const bool theShapesOnly )
191 if ( !theShapesOnly )
193 int nbSel = aList.Extent();
196 Handle(SALOME_InteractiveObject) anIObj = aList.First();
197 if(anIObj->hasEntry()) {
198 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
199 if ( !appStudy ) return nbSel;
200 _PTR(Study) aStudy = appStudy->studyDS();
202 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
204 _PTR(GenericAttribute) anAttr;
206 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
208 _PTR(AttributeName) aNameAttr ( anAttr );
209 theName = aNameAttr->Value().c_str();
214 theName = QObject::tr("%1_objects").arg(nbSel);
220 GEOM::ListOfGO anObjs;
221 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
222 if ( anObjs.length() == 1 )
223 theName = GetName( anObjs[ 0 ] );
225 theName = QString( "%1_objects" ).arg( anObjs.length() );
227 return anObjs.length();
232 //=================================================================================
233 // function : GetShapeTypeString()
234 // purpose : for a single shape
235 //=================================================================================
236 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
238 if(aShape.IsNull()) {
239 aTypeString = "aNullShape";
242 switch(aShape.ShapeType())
244 case TopAbs_COMPOUND:
246 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND"));
249 case TopAbs_COMPSOLID:
251 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID")) ;
256 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID")) ;
261 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL")) ;
266 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
267 if(surf.GetType() == GeomAbs_Plane) {
268 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE"));
271 else if(surf.GetType() == GeomAbs_Cylinder) {
272 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER"));
275 else if(surf.GetType() == GeomAbs_Sphere) {
276 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE"));
279 else if(surf.GetType() == GeomAbs_Torus) {
280 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS"));
283 else if(surf.GetType() == GeomAbs_Cone) {
284 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE"));
288 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE"));
294 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE"));
299 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
300 if(curv.GetType() == GeomAbs_Line) {
301 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
302 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE"));
304 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
307 else if(curv.GetType() == GeomAbs_Circle) {
309 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE"));
311 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC"));
315 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
321 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX"));
326 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE"));
334 //=======================================================================
335 // function : ConvertIORinGEOMAISShape()
337 //=======================================================================
338 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
340 Handle(GEOM_AISShape) resultShape;
343 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
344 if ( !appStudy ) return resultShape;
345 _PTR(Study) aStudy = appStudy->studyDS();
347 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
351 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
353 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
354 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
355 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
357 AIS_ListOfInteractive List;
358 ic->DisplayedObjects(List);
359 AIS_ListOfInteractive List1;
360 ic->ObjectsInCollector(List1);
363 AIS_ListIteratorOfListOfInteractive ite(List);
365 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
366 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
368 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
369 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
370 if(!onlyInActiveView ||
371 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
387 //=======================================================================
388 // function : ConvertIORinGEOMActor()
390 //=======================================================================
391 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
395 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
396 if ( !appStudy ) return GEOM_Actor::New();
397 _PTR(Study) aStudy = appStudy->studyDS();
399 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
401 return GEOM_Actor::New();
403 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
405 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
406 if (it.current()->getViewManager()->getType() == VTKViewer_Viewer::Type()) {
407 VTKViewer_ViewWindow* aVTKViewWindow = (VTKViewer_ViewWindow*)it.current();
408 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
409 vtkActorCollection* theActors = Renderer->GetActors();
410 theActors->InitTraversal();
411 vtkActor *ac = theActors->GetNextActor();
413 if( ac->IsA("GEOM_Actor")) {
414 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
415 if(anActor->hasIO()) {
416 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
417 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
418 if(!onlyInActiveView ||
419 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
426 ac = theActors->GetNextActor();
431 return GEOM_Actor::New();
434 //=======================================================================
435 // function : GetAIS()
437 //=======================================================================
438 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
439 const bool isOnlyInActiveView )
441 if ( theIO.IsNull() || !theIO->hasEntry() )
442 return Handle(AIS_InteractiveObject)();
444 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
446 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
447 if (it.current()->getViewManager()->getType() != OCCViewer_Viewer::Type())
449 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
451 AIS_ListOfInteractive aList;
452 anIC->DisplayedObjects( aList );
453 anIC->ObjectsInCollector( aList );
455 AIS_ListIteratorOfListOfInteractive anIter( aList );
456 for ( ; anIter.More(); anIter.Next() )
458 Handle(SALOME_InteractiveObject) anObj =
459 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
461 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
463 if( isOnlyInActiveView )
465 if ( it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
466 return anIter.Value();
469 return anIter.Value();
474 return Handle(AIS_InteractiveObject)();
478 //=======================================================================
479 // function : ConvertIOinGEOMAISShape()
481 //=======================================================================
482 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
484 Handle(GEOM_AISShape) res;
486 if ( !IO->hasEntry() )
492 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
494 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
495 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
496 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
498 AIS_ListOfInteractive List;
499 ic->DisplayedObjects(List);
500 AIS_ListOfInteractive List1;
501 ic->ObjectsInCollector(List1);
504 AIS_ListIteratorOfListOfInteractive ite(List);
507 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
509 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
512 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
516 if(it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
539 //=======================================================================
540 // function : ConvertIOinGEOMShape()
542 //=======================================================================
543 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
545 GEOM::GEOM_Object_var aShape;
550 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
551 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
552 _PTR(Study) aStudy = appStudy->studyDS();
554 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
555 _PTR(GenericAttribute) anAttr;
557 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
558 _PTR(AttributeIOR) anIOR ( anAttr );
559 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
560 if(!CORBA::is_nil(aShape))
562 return aShape._retn();
566 return GEOM::GEOM_Object::_nil();
570 //=======================================================================
571 // function : ConvertListOfIOInListOfIOR()
573 //=======================================================================
574 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
576 int nbSel = aList.Extent();
577 listIOR.length(nbSel);
579 SALOME_ListIteratorOfListIO It(aList);
580 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
581 if ( !appStudy ) return;
582 _PTR(Study) aStudy = appStudy->studyDS();
584 for(int i=0; It.More(); It.Next(), i++) {
585 Handle(SALOME_InteractiveObject) IObject = It.Value();
586 if(IObject->hasEntry()) {
587 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
588 _PTR(GenericAttribute) anAttr;
589 if(obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
590 _PTR(AttributeIOR) anIOR (anAttr);
591 CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->ConvertIORToObject(anIOR->Value());
592 if(theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
593 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
603 //=======================================================================
604 // function : ConvertIOinGEOMObject()
606 //=======================================================================
607 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
608 Standard_Boolean& theResult )
610 theResult = Standard_False;
611 GEOM::GEOM_Object_var aReturnObject;
612 if ( !theIO.IsNull() )
614 const char* anEntry = theIO->getEntry();
616 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
617 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
618 _PTR(Study) aStudy = appStudy->studyDS();
620 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
624 aReturnObject = GEOM::GEOM_Object::_narrow( dynamic_cast<SALOMEDS_SObject*>(aSObj.get())->GetObject() );
625 theResult = !CORBA::is_nil( aReturnObject );
628 return aReturnObject._retn();
632 //=======================================================================
633 // function : ConvertListOfIOInListOfGO()
635 //=======================================================================
636 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
637 GEOM::ListOfGO& theListGO,
638 const bool theShapesOnly )
640 int nbSel = theList.Extent();
641 theListGO.length( nbSel );
642 SALOME_ListIteratorOfListIO anIter( theList );
644 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
645 if ( !appStudy ) return;
646 _PTR(Study) aStudy = appStudy->studyDS();
649 for ( int i=0; anIter.More(); anIter.Next(), i++ )
651 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
652 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
656 GEOM::GEOM_Object_var aGeomObj =
657 GEOM::GEOM_Object::_narrow(dynamic_cast<SALOMEDS_SObject*>(aSObj.get())->GetObject());
658 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
659 theListGO[ j++ ] = aGeomObj;
663 theListGO.length( j );
666 //=================================================================================
667 // function : CreateArrowForLinearEdge()
668 // purpose : Create a cone topology to be used to display an arrow in the middle
669 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
670 //=================================================================================
671 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
673 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
674 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
677 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
678 Handle( V3d_View) view3d = vp3d->getView();
679 Standard_Real Width, Height;
680 view3d->Size(Width, Height);
681 const Standard_Real aHeight = (Width + Height) / 50.0;
684 Standard_Real first, last;
685 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
689 const Standard_Real param = (first+last) / 2.0;
690 gp_Pnt middleParamPoint;
692 curv->D1( param, middleParamPoint, V1);
693 if(V1.Magnitude() < Precision::Confusion())
696 /* Topology orientation not geom orientation */
697 if(tds.Orientation() == TopAbs_REVERSED)
700 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
701 const Standard_Real radius1 = aHeight / 5.0;
702 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
703 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
707 catch(Standard_Failure) {
708 // OCC failures are hard to catch in GUI.
709 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
710 // in SALOME environment : compilation error !
716 //=================================================================================
717 // function : VertexToPoint()
718 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
719 //=================================================================================
720 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
722 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
724 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
729 //=================================================================================
730 // function : GetBipointDxDyDz()
732 //=================================================================================
733 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
735 dx = P2.X() - P1.X();
736 dy = P2.Y() - P1.Y();
737 dz = P2.Z() - P1.Z();
742 //=================================================================================
743 // function : LinearEdgeExtremities()
744 // purpose : If S can be converted in a linear edge and if initial an final points
745 // : distance is sufficient, returns true else returns false.
746 // : Resulting points are respectively P1 and P2
747 //=================================================================================
748 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
750 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
752 BRepAdaptor_Curve curv(TopoDS::Edge(S));
753 if(curv.GetType() != GeomAbs_Line)
756 curv.D0(curv.FirstParameter(), P1);
757 curv.D0(curv.LastParameter(), P2);
759 if(P1.Distance(P2) <= Precision::Confusion())
766 //=======================================================================
767 // function : Parameter()
768 // purpose : return a parameter (float) from a dialog box
770 // avalue1 : is a float or integer used as a default value displayed
771 // aTitle1 : is the title for aValue1
772 // aTitle : is the main title
773 // bottom : maximum value to be entered
774 // top : minimum value to be entered
775 // decimals : number of decimals
776 //=======================================================================
777 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
779 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
780 aTitle, TRUE, 0, bottom, top, decimals);
781 int r = Dialog->exec();
783 if(r == QDialog::Accepted) {
785 X = Dialog->getValue();
788 res = Standard_False;
794 //=======================================================================
795 // function : SelectionByNameInDialogs()
796 // purpose : Called when user has entered a name of object in a LineEdit.
797 // : The selection is changed. Dialog box will receive the
798 // : corresponding signal to manage this event.
799 //=======================================================================
800 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
802 /* Find SObject with name in component GEOM */
803 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
804 if ( !appStudy ) return false;
805 _PTR(Study) ST = appStudy->studyDS();
807 std::vector<_PTR(SObject)> listSO;
808 listSO = ST->FindObjectByName(objectUserName.latin1(), "GEOM");
810 if(listSO.size() < 1) {
811 const QString caption = QObject::tr("GEOM_WRN_WARNING");
812 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
813 const QString button0 = QObject::tr("GEOM_BUT_OK");
814 SUIT_MessageBox::error1(aWidget, caption, text, button0);
817 /* More than one object with same name */
818 if(listSO.size() > 1) {
819 const QString caption = QObject::tr("GEOM_WRN_WARNING");
820 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
821 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
822 SUIT_MessageBox::error1(aWidget, caption, text, button0) ;
827 _PTR(SObject) theObj ( listSO[0] );
828 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
829 char* aCopyobjectUserName = CORBA::string_dup(objectUserName);
830 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
831 delete(aCopyobjectUserName);
833 /* Add as a selected object */
834 /* Clear any previous selection : */
835 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
836 // Sel->ClearIObjects(); //mzn
837 // Sel->AddIObject(SI); //mzn
842 //=======================================================================
843 // function : DefineDlgPosition()
844 // purpose : Define x and y the default position for a dialog box
845 //=======================================================================
846 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
848 /* Here the position is on the bottom right corner - 10 */
849 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
850 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
851 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
856 //=======================================================================
857 // function : GetDefaultName()
858 // purpose : Generates default names
859 //=======================================================================
860 QString GEOMBase::GetDefaultName(const QString& theOperation)
864 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
865 if ( !appStudy ) return aName;
866 _PTR(Study) aStudy = appStudy->studyDS();
872 aName = theOperation+"_"+QString::number(++aNumber);
873 obj = aStudy->FindObject(aName.latin1());
881 //=======================================================================
882 // function : ShowErrorMessage()
883 // purpose : Shows message box with error code and comment
884 //=======================================================================
885 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
887 QString anErrorCode(theErrorCode);
888 QString aComment(theComment);
891 if (!anErrorCode.isEmpty())
892 aText.append("\n" + QObject::tr(anErrorCode));
893 if (!aComment.isEmpty())
894 aText.append("\n" + QString(theComment));
896 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
897 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
901 //=======================================================================
902 // function : GetObjectFromIOR()
903 // purpose : returns a GEOM_Object by given IOR (string)
904 //=======================================================================
905 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
907 GEOM::GEOM_Object_var anObject;
908 if ( theIOR == NULL || strlen( theIOR ) == 0 )
909 return anObject._retn(); // returning nil object
911 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
912 return anObject._retn();
915 //=======================================================================
916 // function : GetIORFromObject()
917 // purpose : returns IOR of a given GEOM_Object
918 //=======================================================================
919 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
921 if ( CORBA::is_nil( theObject ) )
924 return SalomeApp_Application::orb()->object_to_string( theObject );
927 //=======================================================================
928 // function : GetShape()
929 // purpose : returns a TopoDS_Shape stored in GEOM_Object
930 //=======================================================================
931 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
933 if ( !CORBA::is_nil( theObject ) )
935 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
936 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
938 theShape = aTopoDSShape;
945 //=======================================================================
946 // function : GetName()
947 // purpose : Get name of object
948 //=======================================================================
949 const char* GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
951 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
955 string anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
958 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( anIOR ) );
960 _PTR(GenericAttribute) anAttr;
962 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
964 _PTR(AttributeName) aNameAttr ( anAttr );
965 return aNameAttr->Value().c_str();
973 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
975 return !theObj->_is_nil() && theObj->IsShape();