1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 : GetShapeFromIOR()
94 // purpose : exist also as static method !
95 //=====================================================================================
96 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
99 if(IOR.stripWhiteSpace().isEmpty())
102 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object((char*)(IOR.latin1()));
103 if(CORBA::is_nil(obj))
105 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
106 if (GeomObject->_is_nil())
109 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
114 //=====================================================================================
115 // function : GetIndex()
116 // purpose : Get the index of a sub shape in a main shape : index start at 1
117 //=====================================================================================
118 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
120 if(shape.IsNull() || subshape.IsNull())
123 TopTools_IndexedMapOfShape anIndices;
124 TopExp::MapShapes(shape, anIndices);
125 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
131 //=======================================================================
132 // function : GetTopoFromSelection()
133 // purpose : Define tds from a single selection and retuen true
134 //=======================================================================
135 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
137 if(aList.Extent() != 1)
140 Handle(SALOME_InteractiveObject) IO = aList.First();
143 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
144 if ( !appStudy ) return false;
145 _PTR(Study) aStudy = appStudy->studyDS();
147 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
148 _PTR(GenericAttribute) anAttr;
150 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
151 _PTR(AttributeIOR) anIOR ( anAttr );
152 tds = GetShapeFromIOR(anIOR->Value().c_str());
164 //=======================================================================
165 // function : GetNameOfSelectedIObjects()
166 // purpose : Define the name geom++ or other name of mono or multi sel.
167 //=======================================================================
168 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
170 const bool theShapesOnly )
172 if ( !theShapesOnly )
174 int nbSel = aList.Extent();
177 Handle(SALOME_InteractiveObject) anIObj = aList.First();
178 if(anIObj->hasEntry()) {
179 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
180 if ( !appStudy ) return nbSel;
181 _PTR(Study) aStudy = appStudy->studyDS();
183 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
185 _PTR(GenericAttribute) anAttr;
187 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
189 _PTR(AttributeName) aNameAttr ( anAttr );
190 theName = aNameAttr->Value().c_str();
195 theName = QObject::tr("%1_objects").arg(nbSel);
201 GEOM::ListOfGO anObjs;
202 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
203 if ( anObjs.length() == 1 ) {
204 theName = GetName( anObjs[ 0 ] );
207 theName = QString( "%1_objects" ).arg( anObjs.length() );
209 return anObjs.length();
214 //=================================================================================
215 // function : GetShapeTypeString()
216 // purpose : for a single shape
217 //=================================================================================
218 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
220 if(aShape.IsNull()) {
221 aTypeString = "aNullShape";
224 switch(aShape.ShapeType())
226 case TopAbs_COMPOUND:
228 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND"));
231 case TopAbs_COMPSOLID:
233 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID")) ;
238 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID")) ;
243 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL")) ;
248 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
249 if(surf.GetType() == GeomAbs_Plane) {
250 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE"));
253 else if(surf.GetType() == GeomAbs_Cylinder) {
254 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER"));
257 else if(surf.GetType() == GeomAbs_Sphere) {
258 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE"));
261 else if(surf.GetType() == GeomAbs_Torus) {
262 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS"));
265 else if(surf.GetType() == GeomAbs_Cone) {
266 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE"));
270 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE"));
276 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE"));
281 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
282 if(curv.GetType() == GeomAbs_Line) {
283 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
284 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE"));
286 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
289 else if(curv.GetType() == GeomAbs_Circle) {
291 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE"));
293 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC"));
297 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
303 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX"));
308 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE"));
316 //=======================================================================
317 // function : ConvertIORinGEOMAISShape()
319 //=======================================================================
320 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
322 Handle(GEOM_AISShape) resultShape;
325 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
326 if ( !appStudy ) return resultShape;
327 _PTR(Study) aStudy = appStudy->studyDS();
329 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
333 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
335 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
336 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
337 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
339 AIS_ListOfInteractive List;
340 ic->DisplayedObjects(List);
341 AIS_ListOfInteractive List1;
342 ic->ObjectsInCollector(List1);
345 AIS_ListIteratorOfListOfInteractive ite(List);
347 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
348 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
350 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
351 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
352 if(!onlyInActiveView ||
353 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
369 //=======================================================================
370 // function : ConvertIORinGEOMActor()
372 //=======================================================================
373 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
377 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
378 if ( !appStudy ) return GEOM_Actor::New();
379 _PTR(Study) aStudy = appStudy->studyDS();
381 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
383 return GEOM_Actor::New();
385 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
387 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
388 if (it.current()->getViewManager()->getType() == SVTK_Viewer::Type()) {
389 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( it.current() );
390 if( !aVTKViewWindow )
392 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
393 vtkActorCollection* theActors = Renderer->GetActors();
394 theActors->InitTraversal();
395 vtkActor *ac = theActors->GetNextActor();
397 if( ac->IsA("GEOM_Actor")) {
398 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
399 if(anActor->hasIO()) {
400 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
401 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
402 if(!onlyInActiveView ||
403 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
410 ac = theActors->GetNextActor();
415 return GEOM_Actor::New();
418 //=======================================================================
419 // function : GetAIS()
421 //=======================================================================
422 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
423 const bool isOnlyInActiveView )
425 if ( theIO.IsNull() || !theIO->hasEntry() )
426 return Handle(AIS_InteractiveObject)();
428 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
430 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
431 if (it.current()->getViewManager()->getType() != OCCViewer_Viewer::Type())
433 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
435 AIS_ListOfInteractive aList;
436 anIC->DisplayedObjects( aList );
437 anIC->ObjectsInCollector( aList );
439 AIS_ListIteratorOfListOfInteractive anIter( aList );
440 for ( ; anIter.More(); anIter.Next() )
442 Handle(SALOME_InteractiveObject) anObj =
443 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
445 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
447 if( isOnlyInActiveView )
449 if ( it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
450 return anIter.Value();
453 return anIter.Value();
458 return Handle(AIS_InteractiveObject)();
462 //=======================================================================
463 // function : ConvertIOinGEOMAISShape()
465 //=======================================================================
466 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
468 Handle(GEOM_AISShape) res;
470 if ( !IO->hasEntry() )
476 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
478 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
479 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
480 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
482 AIS_ListOfInteractive List;
483 ic->DisplayedObjects(List);
484 AIS_ListOfInteractive List1;
485 ic->ObjectsInCollector(List1);
488 AIS_ListIteratorOfListOfInteractive ite(List);
491 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
493 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
496 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
500 if(it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
523 //=======================================================================
524 // function : ConvertIOinGEOMShape()
526 //=======================================================================
527 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
529 GEOM::GEOM_Object_var aShape;
534 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
535 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
536 _PTR(Study) aStudy = appStudy->studyDS();
538 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
539 _PTR(GenericAttribute) anAttr;
541 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
542 _PTR(AttributeIOR) anIOR ( anAttr );
543 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
544 if(!CORBA::is_nil(aShape))
546 return aShape._retn();
550 return GEOM::GEOM_Object::_nil();
554 //=======================================================================
555 // function : ConvertListOfIOInListOfIOR()
557 //=======================================================================
558 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
560 int nbSel = aList.Extent();
561 listIOR.length(nbSel);
563 SALOME_ListIteratorOfListIO It(aList);
564 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
565 ( SUIT_Session::session()->activeApplication()->activeStudy() );
566 if ( !appStudy ) return;
567 _PTR(Study) aStudy = appStudy->studyDS();
569 for (int i=0; It.More(); It.Next(), i++) {
570 Handle(SALOME_InteractiveObject) IObject = It.Value();
571 if (IObject->hasEntry()) {
572 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
573 _PTR(GenericAttribute) anAttr;
574 if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
575 _PTR(AttributeIOR) anIOR (anAttr);
576 //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
577 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
578 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
579 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
580 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
590 //=======================================================================
591 // function : ConvertIOinGEOMObject()
593 //=======================================================================
594 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
595 Standard_Boolean& theResult )
597 theResult = Standard_False;
598 GEOM::GEOM_Object_var aReturnObject;
599 if ( !theIO.IsNull() )
601 const char* anEntry = theIO->getEntry();
603 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
604 ( SUIT_Session::session()->activeApplication()->activeStudy() );
605 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
606 _PTR(Study) aStudy = appStudy->studyDS();
608 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
612 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
613 theResult = !CORBA::is_nil( aReturnObject );
616 return aReturnObject._retn();
620 //=======================================================================
621 // function : ConvertListOfIOInListOfGO()
623 //=======================================================================
624 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
625 GEOM::ListOfGO& theListGO,
626 const bool theShapesOnly )
628 int nbSel = theList.Extent();
629 theListGO.length( nbSel );
630 SALOME_ListIteratorOfListIO anIter( theList );
632 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
633 if ( !appStudy ) return;
634 _PTR(Study) aStudy = appStudy->studyDS();
637 for ( int i=0; anIter.More(); anIter.Next(), i++ )
639 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
640 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
644 GEOM::GEOM_Object_var aGeomObj =
645 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
646 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
647 theListGO[ j++ ] = aGeomObj;
651 theListGO.length( j );
654 //=================================================================================
655 // function : CreateArrowForLinearEdge()
656 // purpose : Create a cone topology to be used to display an arrow in the middle
657 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
658 //=================================================================================
659 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
661 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
662 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
665 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
666 Handle( V3d_View) view3d = vp3d->getView();
667 Standard_Real Width, Height;
668 view3d->Size(Width, Height);
669 const Standard_Real aHeight = (Width + Height) / 50.0;
672 Standard_Real first, last;
673 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
677 const Standard_Real param = (first+last) / 2.0;
678 gp_Pnt middleParamPoint;
680 curv->D1( param, middleParamPoint, V1);
681 if(V1.Magnitude() < Precision::Confusion())
684 /* Topology orientation not geom orientation */
685 if(tds.Orientation() == TopAbs_REVERSED)
688 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
689 const Standard_Real radius1 = aHeight / 5.0;
690 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
691 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
695 catch(Standard_Failure) {
696 // OCC failures are hard to catch in GUI.
697 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
698 // in SALOME environment : compilation error !
704 //=================================================================================
705 // function : VertexToPoint()
706 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
707 //=================================================================================
708 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
710 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
712 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
717 //=================================================================================
718 // function : GetBipointDxDyDz()
720 //=================================================================================
721 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
723 dx = P2.X() - P1.X();
724 dy = P2.Y() - P1.Y();
725 dz = P2.Z() - P1.Z();
730 //=================================================================================
731 // function : LinearEdgeExtremities()
732 // purpose : If S can be converted in a linear edge and if initial an final points
733 // : distance is sufficient, returns true else returns false.
734 // : Resulting points are respectively P1 and P2
735 //=================================================================================
736 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
738 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
740 BRepAdaptor_Curve curv(TopoDS::Edge(S));
741 if(curv.GetType() != GeomAbs_Line)
744 curv.D0(curv.FirstParameter(), P1);
745 curv.D0(curv.LastParameter(), P2);
747 if(P1.Distance(P2) <= Precision::Confusion())
754 //=======================================================================
755 // function : Parameter()
756 // purpose : return a parameter (float) from a dialog box
758 // avalue1 : is a float or integer used as a default value displayed
759 // aTitle1 : is the title for aValue1
760 // aTitle : is the main title
761 // bottom : maximum value to be entered
762 // top : minimum value to be entered
763 // decimals : number of decimals
764 //=======================================================================
765 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
767 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
768 aTitle, TRUE, 0, bottom, top, decimals);
769 int r = Dialog->exec();
771 if(r == QDialog::Accepted) {
773 X = Dialog->getValue();
776 res = Standard_False;
782 //=======================================================================
783 // function : SelectionByNameInDialogs()
784 // purpose : Called when user has entered a name of object in a LineEdit.
785 // : The selection is changed. Dialog box will receive the
786 // : corresponding signal to manage this event.
787 //=======================================================================
788 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
790 /* Find SObject with name in component GEOM */
791 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
792 if ( !appStudy ) return false;
793 _PTR(Study) ST = appStudy->studyDS();
795 std::vector<_PTR(SObject)> listSO;
796 listSO = ST->FindObjectByName(objectUserName.latin1(), "GEOM");
798 if(listSO.size() < 1) {
799 const QString caption = QObject::tr("GEOM_WRN_WARNING");
800 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
801 const QString button0 = QObject::tr("GEOM_BUT_OK");
802 SUIT_MessageBox::error1(aWidget, caption, text, button0);
805 /* More than one object with same name */
806 if(listSO.size() > 1) {
807 const QString caption = QObject::tr("GEOM_WRN_WARNING");
808 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
809 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
810 SUIT_MessageBox::error1(aWidget, caption, text, button0) ;
815 _PTR(SObject) theObj ( listSO[0] );
816 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
817 char* aCopyobjectUserName = CORBA::string_dup(objectUserName);
818 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
819 delete(aCopyobjectUserName);
821 /* Add as a selected object */
822 /* Clear any previous selection : */
823 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
824 // Sel->ClearIObjects(); //mzn
825 // Sel->AddIObject(SI); //mzn
830 //=======================================================================
831 // function : DefineDlgPosition()
832 // purpose : Define x and y the default position for a dialog box
833 //=======================================================================
834 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
836 /* Here the position is on the bottom right corner - 10 */
837 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
838 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
839 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
844 //=======================================================================
845 // function : GetDefaultName()
846 // purpose : Generates default names
847 //=======================================================================
848 QString GEOMBase::GetDefaultName(const QString& theOperation)
852 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
853 if ( !appStudy ) return aName;
854 _PTR(Study) aStudy = appStudy->studyDS();
860 aName = theOperation+"_"+QString::number(++aNumber);
861 obj = aStudy->FindObject(aName.latin1());
869 //=======================================================================
870 // function : ShowErrorMessage()
871 // purpose : Shows message box with error code and comment
872 //=======================================================================
873 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
875 QString anErrorCode(theErrorCode);
876 QString aComment(theComment);
879 if (!anErrorCode.isEmpty())
880 aText.append("\n" + QObject::tr(anErrorCode));
881 if (!aComment.isEmpty())
882 aText.append("\n" + QString(theComment));
884 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
885 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
889 //=======================================================================
890 // function : GetObjectFromIOR()
891 // purpose : returns a GEOM_Object by given IOR (string)
892 //=======================================================================
893 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
895 GEOM::GEOM_Object_var anObject;
896 if ( theIOR == NULL || strlen( theIOR ) == 0 )
897 return anObject._retn(); // returning nil object
899 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
900 return anObject._retn();
903 //=======================================================================
904 // function : GetIORFromObject()
905 // purpose : returns IOR of a given GEOM_Object
906 //=======================================================================
907 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
909 if ( CORBA::is_nil( theObject ) )
912 return SalomeApp_Application::orb()->object_to_string( theObject );
915 //=======================================================================
916 // function : GetShape()
917 // purpose : returns a TopoDS_Shape stored in GEOM_Object
918 //=======================================================================
919 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
921 if ( !CORBA::is_nil( theObject ) )
923 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
924 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
926 theShape = aTopoDSShape;
933 //=======================================================================
934 // function : GetName()
935 // purpose : Get name of object
936 //=======================================================================
937 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
939 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
943 string anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
946 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( anIOR ) );
948 _PTR(GenericAttribute) anAttr;
950 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
952 _PTR(AttributeName) aNameAttr ( anAttr );
953 return QString( aNameAttr->Value().c_str() );
961 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
963 return !theObj->_is_nil() && theObj->IsShape();