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"
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() == VTKViewer_Viewer::Type()) {
406 VTKViewer_ViewWindow* aVTKViewWindow = (VTKViewer_ViewWindow*)it.current();
407 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
408 vtkActorCollection* theActors = Renderer->GetActors();
409 theActors->InitTraversal();
410 vtkActor *ac = theActors->GetNextActor();
412 if( ac->IsA("GEOM_Actor")) {
413 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
414 if(anActor->hasIO()) {
415 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
416 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
417 if(!onlyInActiveView ||
418 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
425 ac = theActors->GetNextActor();
430 return GEOM_Actor::New();
433 //=======================================================================
434 // function : GetAIS()
436 //=======================================================================
437 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
438 const bool isOnlyInActiveView )
440 if ( theIO.IsNull() || !theIO->hasEntry() )
441 return Handle(AIS_InteractiveObject)();
443 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
445 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
446 if (it.current()->getViewManager()->getType() != OCCViewer_Viewer::Type())
448 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
450 AIS_ListOfInteractive aList;
451 anIC->DisplayedObjects( aList );
452 anIC->ObjectsInCollector( aList );
454 AIS_ListIteratorOfListOfInteractive anIter( aList );
455 for ( ; anIter.More(); anIter.Next() )
457 Handle(SALOME_InteractiveObject) anObj =
458 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
460 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
462 if( isOnlyInActiveView )
464 if ( it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
465 return anIter.Value();
468 return anIter.Value();
473 return Handle(AIS_InteractiveObject)();
477 //=======================================================================
478 // function : ConvertIOinGEOMAISShape()
480 //=======================================================================
481 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
483 Handle(GEOM_AISShape) res;
485 if ( !IO->hasEntry() )
491 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
493 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
494 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
495 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
497 AIS_ListOfInteractive List;
498 ic->DisplayedObjects(List);
499 AIS_ListOfInteractive List1;
500 ic->ObjectsInCollector(List1);
503 AIS_ListIteratorOfListOfInteractive ite(List);
506 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
508 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
511 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
515 if(it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
538 //=======================================================================
539 // function : ConvertIOinGEOMShape()
541 //=======================================================================
542 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
544 GEOM::GEOM_Object_var aShape;
549 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
550 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
551 _PTR(Study) aStudy = appStudy->studyDS();
553 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
554 _PTR(GenericAttribute) anAttr;
556 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
557 _PTR(AttributeIOR) anIOR ( anAttr );
558 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
559 if(!CORBA::is_nil(aShape))
561 return aShape._retn();
565 return GEOM::GEOM_Object::_nil();
569 //=======================================================================
570 // function : ConvertListOfIOInListOfIOR()
572 //=======================================================================
573 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
575 int nbSel = aList.Extent();
576 listIOR.length(nbSel);
578 SALOME_ListIteratorOfListIO It(aList);
579 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
580 ( 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*>
592 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
593 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
594 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
595 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
605 //=======================================================================
606 // function : ConvertIOinGEOMObject()
608 //=======================================================================
609 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
610 Standard_Boolean& theResult )
612 theResult = Standard_False;
613 GEOM::GEOM_Object_var aReturnObject;
614 if ( !theIO.IsNull() )
616 const char* anEntry = theIO->getEntry();
618 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
619 ( SUIT_Session::session()->activeApplication()->activeStudy() );
620 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
621 _PTR(Study) aStudy = appStudy->studyDS();
623 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
627 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
628 theResult = !CORBA::is_nil( aReturnObject );
631 return aReturnObject._retn();
635 //=======================================================================
636 // function : ConvertListOfIOInListOfGO()
638 //=======================================================================
639 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
640 GEOM::ListOfGO& theListGO,
641 const bool theShapesOnly )
643 int nbSel = theList.Extent();
644 theListGO.length( nbSel );
645 SALOME_ListIteratorOfListIO anIter( theList );
647 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
648 if ( !appStudy ) return;
649 _PTR(Study) aStudy = appStudy->studyDS();
652 for ( int i=0; anIter.More(); anIter.Next(), i++ )
654 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
655 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
659 GEOM::GEOM_Object_var aGeomObj =
660 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
661 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
662 theListGO[ j++ ] = aGeomObj;
666 theListGO.length( j );
669 //=================================================================================
670 // function : CreateArrowForLinearEdge()
671 // purpose : Create a cone topology to be used to display an arrow in the middle
672 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
673 //=================================================================================
674 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
676 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
677 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
680 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
681 Handle( V3d_View) view3d = vp3d->getView();
682 Standard_Real Width, Height;
683 view3d->Size(Width, Height);
684 const Standard_Real aHeight = (Width + Height) / 50.0;
687 Standard_Real first, last;
688 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
692 const Standard_Real param = (first+last) / 2.0;
693 gp_Pnt middleParamPoint;
695 curv->D1( param, middleParamPoint, V1);
696 if(V1.Magnitude() < Precision::Confusion())
699 /* Topology orientation not geom orientation */
700 if(tds.Orientation() == TopAbs_REVERSED)
703 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
704 const Standard_Real radius1 = aHeight / 5.0;
705 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
706 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
710 catch(Standard_Failure) {
711 // OCC failures are hard to catch in GUI.
712 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
713 // in SALOME environment : compilation error !
719 //=================================================================================
720 // function : VertexToPoint()
721 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
722 //=================================================================================
723 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
725 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
727 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
732 //=================================================================================
733 // function : GetBipointDxDyDz()
735 //=================================================================================
736 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
738 dx = P2.X() - P1.X();
739 dy = P2.Y() - P1.Y();
740 dz = P2.Z() - P1.Z();
745 //=================================================================================
746 // function : LinearEdgeExtremities()
747 // purpose : If S can be converted in a linear edge and if initial an final points
748 // : distance is sufficient, returns true else returns false.
749 // : Resulting points are respectively P1 and P2
750 //=================================================================================
751 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
753 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
755 BRepAdaptor_Curve curv(TopoDS::Edge(S));
756 if(curv.GetType() != GeomAbs_Line)
759 curv.D0(curv.FirstParameter(), P1);
760 curv.D0(curv.LastParameter(), P2);
762 if(P1.Distance(P2) <= Precision::Confusion())
769 //=======================================================================
770 // function : Parameter()
771 // purpose : return a parameter (float) from a dialog box
773 // avalue1 : is a float or integer used as a default value displayed
774 // aTitle1 : is the title for aValue1
775 // aTitle : is the main title
776 // bottom : maximum value to be entered
777 // top : minimum value to be entered
778 // decimals : number of decimals
779 //=======================================================================
780 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
782 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
783 aTitle, TRUE, 0, bottom, top, decimals);
784 int r = Dialog->exec();
786 if(r == QDialog::Accepted) {
788 X = Dialog->getValue();
791 res = Standard_False;
797 //=======================================================================
798 // function : SelectionByNameInDialogs()
799 // purpose : Called when user has entered a name of object in a LineEdit.
800 // : The selection is changed. Dialog box will receive the
801 // : corresponding signal to manage this event.
802 //=======================================================================
803 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
805 /* Find SObject with name in component GEOM */
806 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
807 if ( !appStudy ) return false;
808 _PTR(Study) ST = appStudy->studyDS();
810 std::vector<_PTR(SObject)> listSO;
811 listSO = ST->FindObjectByName(objectUserName.latin1(), "GEOM");
813 if(listSO.size() < 1) {
814 const QString caption = QObject::tr("GEOM_WRN_WARNING");
815 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
816 const QString button0 = QObject::tr("GEOM_BUT_OK");
817 SUIT_MessageBox::error1(aWidget, caption, text, button0);
820 /* More than one object with same name */
821 if(listSO.size() > 1) {
822 const QString caption = QObject::tr("GEOM_WRN_WARNING");
823 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
824 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
825 SUIT_MessageBox::error1(aWidget, caption, text, button0) ;
830 _PTR(SObject) theObj ( listSO[0] );
831 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
832 char* aCopyobjectUserName = CORBA::string_dup(objectUserName);
833 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
834 delete(aCopyobjectUserName);
836 /* Add as a selected object */
837 /* Clear any previous selection : */
838 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
839 // Sel->ClearIObjects(); //mzn
840 // Sel->AddIObject(SI); //mzn
845 //=======================================================================
846 // function : DefineDlgPosition()
847 // purpose : Define x and y the default position for a dialog box
848 //=======================================================================
849 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
851 /* Here the position is on the bottom right corner - 10 */
852 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
853 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
854 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
859 //=======================================================================
860 // function : GetDefaultName()
861 // purpose : Generates default names
862 //=======================================================================
863 QString GEOMBase::GetDefaultName(const QString& theOperation)
867 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
868 if ( !appStudy ) return aName;
869 _PTR(Study) aStudy = appStudy->studyDS();
875 aName = theOperation+"_"+QString::number(++aNumber);
876 obj = aStudy->FindObject(aName.latin1());
884 //=======================================================================
885 // function : ShowErrorMessage()
886 // purpose : Shows message box with error code and comment
887 //=======================================================================
888 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
890 QString anErrorCode(theErrorCode);
891 QString aComment(theComment);
894 if (!anErrorCode.isEmpty())
895 aText.append("\n" + QObject::tr(anErrorCode));
896 if (!aComment.isEmpty())
897 aText.append("\n" + QString(theComment));
899 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
900 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
904 //=======================================================================
905 // function : GetObjectFromIOR()
906 // purpose : returns a GEOM_Object by given IOR (string)
907 //=======================================================================
908 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
910 GEOM::GEOM_Object_var anObject;
911 if ( theIOR == NULL || strlen( theIOR ) == 0 )
912 return anObject._retn(); // returning nil object
914 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
915 return anObject._retn();
918 //=======================================================================
919 // function : GetIORFromObject()
920 // purpose : returns IOR of a given GEOM_Object
921 //=======================================================================
922 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
924 if ( CORBA::is_nil( theObject ) )
927 return SalomeApp_Application::orb()->object_to_string( theObject );
930 //=======================================================================
931 // function : GetShape()
932 // purpose : returns a TopoDS_Shape stored in GEOM_Object
933 //=======================================================================
934 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
936 if ( !CORBA::is_nil( theObject ) )
938 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
939 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
941 theShape = aTopoDSShape;
948 //=======================================================================
949 // function : GetName()
950 // purpose : Get name of object
951 //=======================================================================
952 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
954 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
958 string anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
961 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( anIOR ) );
963 _PTR(GenericAttribute) anAttr;
965 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
967 _PTR(AttributeName) aNameAttr ( anAttr );
968 return QString( aNameAttr->Value().c_str() );
976 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
978 return !theObj->_is_nil() && theObj->IsShape();