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 "SVTK_RenderWindowInteractor.h"
44 #include "SVTK_ViewModel.h"
45 #include "SVTK_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"
92 //=======================================================================
93 // function : GEOMBase()
94 // purpose : Constructor
95 //=======================================================================
101 //=======================================================================
102 // function : ~GEOMBase()
103 // purpose : Destructor
104 //=======================================================================
105 GEOMBase::~GEOMBase()
109 //=====================================================================================
110 // function : GetShapeFromIOR()
111 // purpose : exist also as static method !
112 //=====================================================================================
113 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
116 if(IOR.stripWhiteSpace().isEmpty())
119 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object((char*)(IOR.latin1()));
120 if(CORBA::is_nil(obj))
122 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
123 if (GeomObject->_is_nil())
126 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
131 //=====================================================================================
132 // function : GetIndex()
133 // purpose : Get the index of a sub shape in a main shape : index start at 1
134 //=====================================================================================
135 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
137 if(shape.IsNull() || subshape.IsNull())
140 TopTools_IndexedMapOfShape anIndices;
141 TopExp::MapShapes(shape, anIndices);
142 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
148 //=======================================================================
149 // function : GetTopoFromSelection()
150 // purpose : Define tds from a single selection and retuen true
151 //=======================================================================
152 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
154 if(aList.Extent() != 1)
157 Handle(SALOME_InteractiveObject) IO = aList.First();
160 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
161 if ( !appStudy ) return false;
162 _PTR(Study) aStudy = appStudy->studyDS();
164 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
165 _PTR(GenericAttribute) anAttr;
167 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
168 _PTR(AttributeIOR) anIOR ( anAttr );
169 tds = GetShapeFromIOR(anIOR->Value().c_str());
181 //=======================================================================
182 // function : GetNameOfSelectedIObjects()
183 // purpose : Define the name geom++ or other name of mono or multi sel.
184 //=======================================================================
185 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
187 const bool theShapesOnly )
189 if ( !theShapesOnly )
191 int nbSel = aList.Extent();
194 Handle(SALOME_InteractiveObject) anIObj = aList.First();
195 if(anIObj->hasEntry()) {
196 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
197 if ( !appStudy ) return nbSel;
198 _PTR(Study) aStudy = appStudy->studyDS();
200 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
202 _PTR(GenericAttribute) anAttr;
204 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
206 _PTR(AttributeName) aNameAttr ( anAttr );
207 theName = aNameAttr->Value().c_str();
212 theName = QObject::tr("%1_objects").arg(nbSel);
218 GEOM::ListOfGO anObjs;
219 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
220 if ( anObjs.length() == 1 ) {
221 theName = GetName( anObjs[ 0 ] );
224 theName = QString( "%1_objects" ).arg( anObjs.length() );
226 return anObjs.length();
231 //=================================================================================
232 // function : GetShapeTypeString()
233 // purpose : for a single shape
234 //=================================================================================
235 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
237 if(aShape.IsNull()) {
238 aTypeString = "aNullShape";
241 switch(aShape.ShapeType())
243 case TopAbs_COMPOUND:
245 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND"));
248 case TopAbs_COMPSOLID:
250 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID")) ;
255 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID")) ;
260 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL")) ;
265 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
266 if(surf.GetType() == GeomAbs_Plane) {
267 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE"));
270 else if(surf.GetType() == GeomAbs_Cylinder) {
271 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER"));
274 else if(surf.GetType() == GeomAbs_Sphere) {
275 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE"));
278 else if(surf.GetType() == GeomAbs_Torus) {
279 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS"));
282 else if(surf.GetType() == GeomAbs_Cone) {
283 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE"));
287 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE"));
293 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE"));
298 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
299 if(curv.GetType() == GeomAbs_Line) {
300 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
301 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE"));
303 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
306 else if(curv.GetType() == GeomAbs_Circle) {
308 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE"));
310 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC"));
314 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
320 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX"));
325 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE"));
333 //=======================================================================
334 // function : ConvertIORinGEOMAISShape()
336 //=======================================================================
337 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
339 Handle(GEOM_AISShape) resultShape;
342 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
343 if ( !appStudy ) return resultShape;
344 _PTR(Study) aStudy = appStudy->studyDS();
346 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
350 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
352 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
353 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
354 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
356 AIS_ListOfInteractive List;
357 ic->DisplayedObjects(List);
358 AIS_ListOfInteractive List1;
359 ic->ObjectsInCollector(List1);
362 AIS_ListIteratorOfListOfInteractive ite(List);
364 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
365 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
367 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
368 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
369 if(!onlyInActiveView ||
370 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
386 //=======================================================================
387 // function : ConvertIORinGEOMActor()
389 //=======================================================================
390 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
394 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
395 if ( !appStudy ) return GEOM_Actor::New();
396 _PTR(Study) aStudy = appStudy->studyDS();
398 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
400 return GEOM_Actor::New();
402 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
404 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
405 if (it.current()->getViewManager()->getType() == SVTK_Viewer::Type()) {
406 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( it.current() );
407 if( !aVTKViewWindow )
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*>
582 ( SUIT_Session::session()->activeApplication()->activeStudy() );
583 if ( !appStudy ) return;
584 _PTR(Study) aStudy = appStudy->studyDS();
586 for (int i=0; It.More(); It.Next(), i++) {
587 Handle(SALOME_InteractiveObject) IObject = It.Value();
588 if (IObject->hasEntry()) {
589 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
590 _PTR(GenericAttribute) anAttr;
591 if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
592 _PTR(AttributeIOR) anIOR (anAttr);
593 //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
594 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
595 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
596 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
597 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
607 //=======================================================================
608 // function : ConvertIOinGEOMObject()
610 //=======================================================================
611 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
612 Standard_Boolean& theResult )
614 theResult = Standard_False;
615 GEOM::GEOM_Object_var aReturnObject;
616 if ( !theIO.IsNull() )
618 const char* anEntry = theIO->getEntry();
620 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
621 ( SUIT_Session::session()->activeApplication()->activeStudy() );
622 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
623 _PTR(Study) aStudy = appStudy->studyDS();
625 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
629 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
630 theResult = !CORBA::is_nil( aReturnObject );
633 return aReturnObject._retn();
637 //=======================================================================
638 // function : ConvertListOfIOInListOfGO()
640 //=======================================================================
641 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
642 GEOM::ListOfGO& theListGO,
643 const bool theShapesOnly )
645 int nbSel = theList.Extent();
646 theListGO.length( nbSel );
647 SALOME_ListIteratorOfListIO anIter( theList );
649 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
650 if ( !appStudy ) return;
651 _PTR(Study) aStudy = appStudy->studyDS();
654 for ( int i=0; anIter.More(); anIter.Next(), i++ )
656 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
657 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
661 GEOM::GEOM_Object_var aGeomObj =
662 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
663 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
664 theListGO[ j++ ] = aGeomObj;
668 theListGO.length( j );
671 //=================================================================================
672 // function : CreateArrowForLinearEdge()
673 // purpose : Create a cone topology to be used to display an arrow in the middle
674 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
675 //=================================================================================
676 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
678 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
679 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
682 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
683 Handle( V3d_View) view3d = vp3d->getView();
684 Standard_Real Width, Height;
685 view3d->Size(Width, Height);
686 const Standard_Real aHeight = (Width + Height) / 50.0;
689 Standard_Real first, last;
690 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
694 const Standard_Real param = (first+last) / 2.0;
695 gp_Pnt middleParamPoint;
697 curv->D1( param, middleParamPoint, V1);
698 if(V1.Magnitude() < Precision::Confusion())
701 /* Topology orientation not geom orientation */
702 if(tds.Orientation() == TopAbs_REVERSED)
705 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
706 const Standard_Real radius1 = aHeight / 5.0;
707 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
708 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
712 catch(Standard_Failure) {
713 // OCC failures are hard to catch in GUI.
714 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
715 // in SALOME environment : compilation error !
721 //=================================================================================
722 // function : VertexToPoint()
723 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
724 //=================================================================================
725 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
727 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
729 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
734 //=================================================================================
735 // function : GetBipointDxDyDz()
737 //=================================================================================
738 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
740 dx = P2.X() - P1.X();
741 dy = P2.Y() - P1.Y();
742 dz = P2.Z() - P1.Z();
747 //=================================================================================
748 // function : LinearEdgeExtremities()
749 // purpose : If S can be converted in a linear edge and if initial an final points
750 // : distance is sufficient, returns true else returns false.
751 // : Resulting points are respectively P1 and P2
752 //=================================================================================
753 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
755 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
757 BRepAdaptor_Curve curv(TopoDS::Edge(S));
758 if(curv.GetType() != GeomAbs_Line)
761 curv.D0(curv.FirstParameter(), P1);
762 curv.D0(curv.LastParameter(), P2);
764 if(P1.Distance(P2) <= Precision::Confusion())
771 //=======================================================================
772 // function : Parameter()
773 // purpose : return a parameter (float) from a dialog box
775 // avalue1 : is a float or integer used as a default value displayed
776 // aTitle1 : is the title for aValue1
777 // aTitle : is the main title
778 // bottom : maximum value to be entered
779 // top : minimum value to be entered
780 // decimals : number of decimals
781 //=======================================================================
782 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
784 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
785 aTitle, TRUE, 0, bottom, top, decimals);
786 int r = Dialog->exec();
788 if(r == QDialog::Accepted) {
790 X = Dialog->getValue();
793 res = Standard_False;
799 //=======================================================================
800 // function : SelectionByNameInDialogs()
801 // purpose : Called when user has entered a name of object in a LineEdit.
802 // : The selection is changed. Dialog box will receive the
803 // : corresponding signal to manage this event.
804 //=======================================================================
805 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
807 /* Find SObject with name in component GEOM */
808 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
809 if ( !appStudy ) return false;
810 _PTR(Study) ST = appStudy->studyDS();
812 std::vector<_PTR(SObject)> listSO;
813 listSO = ST->FindObjectByName(objectUserName.latin1(), "GEOM");
815 if(listSO.size() < 1) {
816 const QString caption = QObject::tr("GEOM_WRN_WARNING");
817 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
818 const QString button0 = QObject::tr("GEOM_BUT_OK");
819 SUIT_MessageBox::error1(aWidget, caption, text, button0);
822 /* More than one object with same name */
823 if(listSO.size() > 1) {
824 const QString caption = QObject::tr("GEOM_WRN_WARNING");
825 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
826 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
827 SUIT_MessageBox::error1(aWidget, caption, text, button0) ;
832 _PTR(SObject) theObj ( listSO[0] );
833 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
834 char* aCopyobjectUserName = CORBA::string_dup(objectUserName);
835 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
836 delete(aCopyobjectUserName);
838 /* Add as a selected object */
839 /* Clear any previous selection : */
840 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
841 // Sel->ClearIObjects(); //mzn
842 // Sel->AddIObject(SI); //mzn
847 //=======================================================================
848 // function : DefineDlgPosition()
849 // purpose : Define x and y the default position for a dialog box
850 //=======================================================================
851 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
853 /* Here the position is on the bottom right corner - 10 */
854 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
855 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
856 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
861 //=======================================================================
862 // function : GetDefaultName()
863 // purpose : Generates default names
864 //=======================================================================
865 QString GEOMBase::GetDefaultName(const QString& theOperation)
869 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
870 if ( !appStudy ) return aName;
871 _PTR(Study) aStudy = appStudy->studyDS();
877 aName = theOperation+"_"+QString::number(++aNumber);
878 obj = aStudy->FindObject(aName.latin1());
886 //=======================================================================
887 // function : ShowErrorMessage()
888 // purpose : Shows message box with error code and comment
889 //=======================================================================
890 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
892 QString anErrorCode(theErrorCode);
893 QString aComment(theComment);
896 if (!anErrorCode.isEmpty())
897 aText.append("\n" + QObject::tr(anErrorCode));
898 if (!aComment.isEmpty())
899 aText.append("\n" + QString(theComment));
901 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
902 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
906 //=======================================================================
907 // function : GetObjectFromIOR()
908 // purpose : returns a GEOM_Object by given IOR (string)
909 //=======================================================================
910 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
912 GEOM::GEOM_Object_var anObject;
913 if ( theIOR == NULL || strlen( theIOR ) == 0 )
914 return anObject._retn(); // returning nil object
916 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
917 return anObject._retn();
920 //=======================================================================
921 // function : GetIORFromObject()
922 // purpose : returns IOR of a given GEOM_Object
923 //=======================================================================
924 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
926 if ( CORBA::is_nil( theObject ) )
929 return SalomeApp_Application::orb()->object_to_string( theObject );
932 //=======================================================================
933 // function : GetShape()
934 // purpose : returns a TopoDS_Shape stored in GEOM_Object
935 //=======================================================================
936 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
938 if ( !CORBA::is_nil( theObject ) )
940 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
941 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
943 theShape = aTopoDSShape;
950 //=======================================================================
951 // function : GetName()
952 // purpose : Get name of object
953 //=======================================================================
954 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
956 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
960 string anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
963 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( anIOR ) );
965 _PTR(GenericAttribute) anAttr;
967 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
969 _PTR(AttributeName) aNameAttr ( anAttr );
970 return QString( aNameAttr->Value().c_str() );
978 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
980 return !theObj->_is_nil() && theObj->IsShape();