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 ] );
226 theName = QString( "%1_objects" ).arg( anObjs.length() );
228 return anObjs.length();
233 //=================================================================================
234 // function : GetShapeTypeString()
235 // purpose : for a single shape
236 //=================================================================================
237 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
239 if(aShape.IsNull()) {
240 aTypeString = "aNullShape";
243 switch(aShape.ShapeType())
245 case TopAbs_COMPOUND:
247 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND"));
250 case TopAbs_COMPSOLID:
252 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID")) ;
257 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID")) ;
262 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL")) ;
267 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
268 if(surf.GetType() == GeomAbs_Plane) {
269 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE"));
272 else if(surf.GetType() == GeomAbs_Cylinder) {
273 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER"));
276 else if(surf.GetType() == GeomAbs_Sphere) {
277 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE"));
280 else if(surf.GetType() == GeomAbs_Torus) {
281 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS"));
284 else if(surf.GetType() == GeomAbs_Cone) {
285 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE"));
289 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE"));
295 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE"));
300 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
301 if(curv.GetType() == GeomAbs_Line) {
302 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
303 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE"));
305 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
308 else if(curv.GetType() == GeomAbs_Circle) {
310 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE"));
312 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC"));
316 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
322 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX"));
327 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE"));
335 //=======================================================================
336 // function : ConvertIORinGEOMAISShape()
338 //=======================================================================
339 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
341 Handle(GEOM_AISShape) resultShape;
344 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
345 if ( !appStudy ) return resultShape;
346 _PTR(Study) aStudy = appStudy->studyDS();
348 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
352 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
354 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
355 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
356 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
358 AIS_ListOfInteractive List;
359 ic->DisplayedObjects(List);
360 AIS_ListOfInteractive List1;
361 ic->ObjectsInCollector(List1);
364 AIS_ListIteratorOfListOfInteractive ite(List);
366 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
367 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
369 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
370 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
371 if(!onlyInActiveView ||
372 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
388 //=======================================================================
389 // function : ConvertIORinGEOMActor()
391 //=======================================================================
392 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
396 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
397 if ( !appStudy ) return GEOM_Actor::New();
398 _PTR(Study) aStudy = appStudy->studyDS();
400 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
402 return GEOM_Actor::New();
404 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
406 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
407 if (it.current()->getViewManager()->getType() == VTKViewer_Viewer::Type()) {
408 VTKViewer_ViewWindow* aVTKViewWindow = (VTKViewer_ViewWindow*)it.current();
409 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
410 vtkActorCollection* theActors = Renderer->GetActors();
411 theActors->InitTraversal();
412 vtkActor *ac = theActors->GetNextActor();
414 if( ac->IsA("GEOM_Actor")) {
415 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
416 if(anActor->hasIO()) {
417 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
418 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
419 if(!onlyInActiveView ||
420 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
427 ac = theActors->GetNextActor();
432 return GEOM_Actor::New();
435 //=======================================================================
436 // function : GetAIS()
438 //=======================================================================
439 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
440 const bool isOnlyInActiveView )
442 if ( theIO.IsNull() || !theIO->hasEntry() )
443 return Handle(AIS_InteractiveObject)();
445 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
447 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
448 if (it.current()->getViewManager()->getType() != OCCViewer_Viewer::Type())
450 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
452 AIS_ListOfInteractive aList;
453 anIC->DisplayedObjects( aList );
454 anIC->ObjectsInCollector( aList );
456 AIS_ListIteratorOfListOfInteractive anIter( aList );
457 for ( ; anIter.More(); anIter.Next() )
459 Handle(SALOME_InteractiveObject) anObj =
460 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
462 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
464 if( isOnlyInActiveView )
466 if ( it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
467 return anIter.Value();
470 return anIter.Value();
475 return Handle(AIS_InteractiveObject)();
479 //=======================================================================
480 // function : ConvertIOinGEOMAISShape()
482 //=======================================================================
483 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
485 Handle(GEOM_AISShape) res;
487 if ( !IO->hasEntry() )
493 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
495 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
496 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
497 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
499 AIS_ListOfInteractive List;
500 ic->DisplayedObjects(List);
501 AIS_ListOfInteractive List1;
502 ic->ObjectsInCollector(List1);
505 AIS_ListIteratorOfListOfInteractive ite(List);
508 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
510 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
513 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
517 if(it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
540 //=======================================================================
541 // function : ConvertIOinGEOMShape()
543 //=======================================================================
544 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
546 GEOM::GEOM_Object_var aShape;
551 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
552 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
553 _PTR(Study) aStudy = appStudy->studyDS();
555 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
556 _PTR(GenericAttribute) anAttr;
558 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
559 _PTR(AttributeIOR) anIOR ( anAttr );
560 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
561 if(!CORBA::is_nil(aShape))
563 return aShape._retn();
567 return GEOM::GEOM_Object::_nil();
571 //=======================================================================
572 // function : ConvertListOfIOInListOfIOR()
574 //=======================================================================
575 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
577 int nbSel = aList.Extent();
578 listIOR.length(nbSel);
580 SALOME_ListIteratorOfListIO It(aList);
581 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
582 if ( !appStudy ) return;
583 _PTR(Study) aStudy = appStudy->studyDS();
585 for(int i=0; It.More(); It.Next(), i++) {
586 Handle(SALOME_InteractiveObject) IObject = It.Value();
587 if(IObject->hasEntry()) {
588 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
589 _PTR(GenericAttribute) anAttr;
590 if(obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
591 _PTR(AttributeIOR) anIOR (anAttr);
592 CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->ConvertIORToObject(anIOR->Value());
593 if(theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
594 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
604 //=======================================================================
605 // function : ConvertIOinGEOMObject()
607 //=======================================================================
608 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
609 Standard_Boolean& theResult )
611 theResult = Standard_False;
612 GEOM::GEOM_Object_var aReturnObject;
613 if ( !theIO.IsNull() )
615 const char* anEntry = theIO->getEntry();
617 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
618 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
619 _PTR(Study) aStudy = appStudy->studyDS();
621 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
625 aReturnObject = GEOM::GEOM_Object::_narrow( dynamic_cast<SALOMEDS_SObject*>(aSObj.get())->GetObject() );
626 theResult = !CORBA::is_nil( aReturnObject );
629 return aReturnObject._retn();
633 //=======================================================================
634 // function : ConvertListOfIOInListOfGO()
636 //=======================================================================
637 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
638 GEOM::ListOfGO& theListGO,
639 const bool theShapesOnly )
641 int nbSel = theList.Extent();
642 theListGO.length( nbSel );
643 SALOME_ListIteratorOfListIO anIter( theList );
645 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
646 if ( !appStudy ) return;
647 _PTR(Study) aStudy = appStudy->studyDS();
650 for ( int i=0; anIter.More(); anIter.Next(), i++ )
652 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
653 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
657 GEOM::GEOM_Object_var aGeomObj =
658 GEOM::GEOM_Object::_narrow(dynamic_cast<SALOMEDS_SObject*>(aSObj.get())->GetObject());
659 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
660 theListGO[ j++ ] = aGeomObj;
664 theListGO.length( j );
667 //=================================================================================
668 // function : CreateArrowForLinearEdge()
669 // purpose : Create a cone topology to be used to display an arrow in the middle
670 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
671 //=================================================================================
672 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
674 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
675 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
678 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
679 Handle( V3d_View) view3d = vp3d->getView();
680 Standard_Real Width, Height;
681 view3d->Size(Width, Height);
682 const Standard_Real aHeight = (Width + Height) / 50.0;
685 Standard_Real first, last;
686 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
690 const Standard_Real param = (first+last) / 2.0;
691 gp_Pnt middleParamPoint;
693 curv->D1( param, middleParamPoint, V1);
694 if(V1.Magnitude() < Precision::Confusion())
697 /* Topology orientation not geom orientation */
698 if(tds.Orientation() == TopAbs_REVERSED)
701 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
702 const Standard_Real radius1 = aHeight / 5.0;
703 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
704 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
708 catch(Standard_Failure) {
709 // OCC failures are hard to catch in GUI.
710 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
711 // in SALOME environment : compilation error !
717 //=================================================================================
718 // function : VertexToPoint()
719 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
720 //=================================================================================
721 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
723 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
725 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
730 //=================================================================================
731 // function : GetBipointDxDyDz()
733 //=================================================================================
734 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
736 dx = P2.X() - P1.X();
737 dy = P2.Y() - P1.Y();
738 dz = P2.Z() - P1.Z();
743 //=================================================================================
744 // function : LinearEdgeExtremities()
745 // purpose : If S can be converted in a linear edge and if initial an final points
746 // : distance is sufficient, returns true else returns false.
747 // : Resulting points are respectively P1 and P2
748 //=================================================================================
749 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
751 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
753 BRepAdaptor_Curve curv(TopoDS::Edge(S));
754 if(curv.GetType() != GeomAbs_Line)
757 curv.D0(curv.FirstParameter(), P1);
758 curv.D0(curv.LastParameter(), P2);
760 if(P1.Distance(P2) <= Precision::Confusion())
767 //=======================================================================
768 // function : Parameter()
769 // purpose : return a parameter (float) from a dialog box
771 // avalue1 : is a float or integer used as a default value displayed
772 // aTitle1 : is the title for aValue1
773 // aTitle : is the main title
774 // bottom : maximum value to be entered
775 // top : minimum value to be entered
776 // decimals : number of decimals
777 //=======================================================================
778 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
780 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
781 aTitle, TRUE, 0, bottom, top, decimals);
782 int r = Dialog->exec();
784 if(r == QDialog::Accepted) {
786 X = Dialog->getValue();
789 res = Standard_False;
795 //=======================================================================
796 // function : SelectionByNameInDialogs()
797 // purpose : Called when user has entered a name of object in a LineEdit.
798 // : The selection is changed. Dialog box will receive the
799 // : corresponding signal to manage this event.
800 //=======================================================================
801 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
803 /* Find SObject with name in component GEOM */
804 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
805 if ( !appStudy ) return false;
806 _PTR(Study) ST = appStudy->studyDS();
808 std::vector<_PTR(SObject)> listSO;
809 listSO = ST->FindObjectByName(objectUserName.latin1(), "GEOM");
811 if(listSO.size() < 1) {
812 const QString caption = QObject::tr("GEOM_WRN_WARNING");
813 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
814 const QString button0 = QObject::tr("GEOM_BUT_OK");
815 SUIT_MessageBox::error1(aWidget, caption, text, button0);
818 /* More than one object with same name */
819 if(listSO.size() > 1) {
820 const QString caption = QObject::tr("GEOM_WRN_WARNING");
821 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
822 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
823 SUIT_MessageBox::error1(aWidget, caption, text, button0) ;
828 _PTR(SObject) theObj ( listSO[0] );
829 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
830 char* aCopyobjectUserName = CORBA::string_dup(objectUserName);
831 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
832 delete(aCopyobjectUserName);
834 /* Add as a selected object */
835 /* Clear any previous selection : */
836 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
837 // Sel->ClearIObjects(); //mzn
838 // Sel->AddIObject(SI); //mzn
843 //=======================================================================
844 // function : DefineDlgPosition()
845 // purpose : Define x and y the default position for a dialog box
846 //=======================================================================
847 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
849 /* Here the position is on the bottom right corner - 10 */
850 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
851 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
852 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
857 //=======================================================================
858 // function : GetDefaultName()
859 // purpose : Generates default names
860 //=======================================================================
861 QString GEOMBase::GetDefaultName(const QString& theOperation)
865 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
866 if ( !appStudy ) return aName;
867 _PTR(Study) aStudy = appStudy->studyDS();
873 aName = theOperation+"_"+QString::number(++aNumber);
874 obj = aStudy->FindObject(aName.latin1());
882 //=======================================================================
883 // function : ShowErrorMessage()
884 // purpose : Shows message box with error code and comment
885 //=======================================================================
886 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
888 QString anErrorCode(theErrorCode);
889 QString aComment(theComment);
892 if (!anErrorCode.isEmpty())
893 aText.append("\n" + QObject::tr(anErrorCode));
894 if (!aComment.isEmpty())
895 aText.append("\n" + QString(theComment));
897 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
898 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
902 //=======================================================================
903 // function : GetObjectFromIOR()
904 // purpose : returns a GEOM_Object by given IOR (string)
905 //=======================================================================
906 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
908 GEOM::GEOM_Object_var anObject;
909 if ( theIOR == NULL || strlen( theIOR ) == 0 )
910 return anObject._retn(); // returning nil object
912 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
913 return anObject._retn();
916 //=======================================================================
917 // function : GetIORFromObject()
918 // purpose : returns IOR of a given GEOM_Object
919 //=======================================================================
920 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
922 if ( CORBA::is_nil( theObject ) )
925 return SalomeApp_Application::orb()->object_to_string( theObject );
928 //=======================================================================
929 // function : GetShape()
930 // purpose : returns a TopoDS_Shape stored in GEOM_Object
931 //=======================================================================
932 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
934 if ( !CORBA::is_nil( theObject ) )
936 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
937 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
939 theShape = aTopoDSShape;
946 //=======================================================================
947 // function : GetName()
948 // purpose : Get name of object
949 //=======================================================================
950 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
952 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
956 string anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
959 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( anIOR ) );
961 _PTR(GenericAttribute) anAttr;
963 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
965 _PTR(AttributeName) aNameAttr ( anAttr );
966 return QString( aNameAttr->Value().c_str() );
974 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
976 return !theObj->_is_nil() && theObj->IsShape();