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>
87 #include "GEOMImpl_Types.hxx"
91 #include "SALOMEDSClient.hxx"
94 //=====================================================================================
95 // function : GetShapeFromIOR()
96 // purpose : exist also as static method !
97 //=====================================================================================
98 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
101 if(IOR.stripWhiteSpace().isEmpty())
104 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object((char*)(IOR.latin1()));
105 if(CORBA::is_nil(obj))
107 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
108 if (GeomObject->_is_nil())
111 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
116 //=====================================================================================
117 // function : GetIndex()
118 // purpose : Get the index of a sub shape in a main shape : index start at 1
119 //=====================================================================================
120 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
122 if(shape.IsNull() || subshape.IsNull())
125 TopTools_IndexedMapOfShape anIndices;
126 TopExp::MapShapes(shape, anIndices);
127 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
133 //=======================================================================
134 // function : GetTopoFromSelection()
135 // purpose : Define tds from a single selection and retuen true
136 //=======================================================================
137 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
139 if(aList.Extent() != 1)
142 Handle(SALOME_InteractiveObject) IO = aList.First();
145 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
146 if ( !appStudy ) return false;
147 _PTR(Study) aStudy = appStudy->studyDS();
149 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
150 _PTR(GenericAttribute) anAttr;
152 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
153 _PTR(AttributeIOR) anIOR ( anAttr );
154 tds = GetShapeFromIOR(anIOR->Value().c_str());
166 //=======================================================================
167 // function : GetNameOfSelectedIObjects()
168 // purpose : Define the name geom++ or other name of mono or multi sel.
169 //=======================================================================
170 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
172 const bool theShapesOnly )
174 if ( !theShapesOnly )
176 int nbSel = aList.Extent();
179 Handle(SALOME_InteractiveObject) anIObj = aList.First();
180 if(anIObj->hasEntry()) {
181 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
182 if ( !appStudy ) return nbSel;
183 _PTR(Study) aStudy = appStudy->studyDS();
185 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
187 _PTR(GenericAttribute) anAttr;
189 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
191 _PTR(AttributeName) aNameAttr ( anAttr );
192 theName = aNameAttr->Value().c_str();
197 theName = QObject::tr("%1_objects").arg(nbSel);
203 GEOM::ListOfGO anObjs;
204 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
205 if ( anObjs.length() == 1 ) {
206 theName = GetName( anObjs[ 0 ] );
209 theName = QString( "%1_objects" ).arg( anObjs.length() );
211 return anObjs.length();
216 //=================================================================================
217 // function : GetShapeTypeString()
218 // purpose : for a single shape
219 //=================================================================================
220 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
222 if(aShape.IsNull()) {
223 aTypeString = "aNullShape";
226 switch(aShape.ShapeType())
228 case TopAbs_COMPOUND:
230 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND"));
233 case TopAbs_COMPSOLID:
235 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID")) ;
240 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID")) ;
245 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL")) ;
250 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
251 if(surf.GetType() == GeomAbs_Plane) {
252 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE"));
255 else if(surf.GetType() == GeomAbs_Cylinder) {
256 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER"));
259 else if(surf.GetType() == GeomAbs_Sphere) {
260 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE"));
263 else if(surf.GetType() == GeomAbs_Torus) {
264 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS"));
267 else if(surf.GetType() == GeomAbs_Cone) {
268 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE"));
272 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE"));
278 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE"));
283 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
284 if(curv.GetType() == GeomAbs_Line) {
285 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
286 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE"));
288 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
291 else if(curv.GetType() == GeomAbs_Circle) {
293 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE"));
295 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC"));
299 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
305 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX"));
310 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE"));
318 //=======================================================================
319 // function : ConvertIORinGEOMAISShape()
321 //=======================================================================
322 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
324 Handle(GEOM_AISShape) resultShape;
327 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
328 if ( !appStudy ) return resultShape;
329 _PTR(Study) aStudy = appStudy->studyDS();
331 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
335 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
337 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
338 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
339 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
341 AIS_ListOfInteractive List;
342 ic->DisplayedObjects(List);
343 AIS_ListOfInteractive List1;
344 ic->ObjectsInCollector(List1);
347 AIS_ListIteratorOfListOfInteractive ite(List);
349 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
350 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
352 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
353 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
354 if(!onlyInActiveView ||
355 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
371 //=======================================================================
372 // function : ConvertIORinGEOMActor()
374 //=======================================================================
375 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
379 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
380 if ( !appStudy ) return GEOM_Actor::New();
381 _PTR(Study) aStudy = appStudy->studyDS();
383 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
385 return GEOM_Actor::New();
387 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
389 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
390 if (it.current()->getViewManager()->getType() == SVTK_Viewer::Type()) {
391 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( it.current() );
392 if( !aVTKViewWindow )
394 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
395 vtkActorCollection* theActors = Renderer->GetActors();
396 theActors->InitTraversal();
397 vtkActor *ac = theActors->GetNextActor();
399 if( ac->IsA("GEOM_Actor")) {
400 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
401 if(anActor->hasIO()) {
402 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
403 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
404 if(!onlyInActiveView ||
405 it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
412 ac = theActors->GetNextActor();
417 return GEOM_Actor::New();
420 //=======================================================================
421 // function : GetAIS()
423 //=======================================================================
424 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
425 const bool isOnlyInActiveView )
427 if ( theIO.IsNull() || !theIO->hasEntry() )
428 return Handle(AIS_InteractiveObject)();
430 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
432 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
433 if (it.current()->getViewManager()->getType() != OCCViewer_Viewer::Type())
435 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
437 AIS_ListOfInteractive aList;
438 anIC->DisplayedObjects( aList );
439 anIC->ObjectsInCollector( aList );
441 AIS_ListIteratorOfListOfInteractive anIter( aList );
442 for ( ; anIter.More(); anIter.Next() )
444 Handle(SALOME_InteractiveObject) anObj =
445 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
447 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
449 if( isOnlyInActiveView )
451 if ( it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
452 return anIter.Value();
455 return anIter.Value();
460 return Handle(AIS_InteractiveObject)();
464 //=======================================================================
465 // function : ConvertIOinGEOMAISShape()
467 //=======================================================================
468 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
470 Handle(GEOM_AISShape) res;
472 if ( !IO->hasEntry() )
478 QPtrList<SUIT_ViewWindow> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
480 for ( QPtrListIterator<SUIT_ViewWindow> it( aViewWindowsList ); it.current(); ++it ) {
481 if (it.current()->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
482 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)it.current()->getViewManager()->getViewModel())->getAISContext();
484 AIS_ListOfInteractive List;
485 ic->DisplayedObjects(List);
486 AIS_ListOfInteractive List1;
487 ic->ObjectsInCollector(List1);
490 AIS_ListIteratorOfListOfInteractive ite(List);
493 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
495 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
498 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
502 if(it.current() == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
525 //=======================================================================
526 // function : ConvertIOinGEOMShape()
528 //=======================================================================
529 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
531 GEOM::GEOM_Object_var aShape;
536 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
537 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
538 _PTR(Study) aStudy = appStudy->studyDS();
540 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
541 _PTR(GenericAttribute) anAttr;
543 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
544 _PTR(AttributeIOR) anIOR ( anAttr );
545 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
546 if(!CORBA::is_nil(aShape))
548 return aShape._retn();
552 return GEOM::GEOM_Object::_nil();
556 //=======================================================================
557 // function : ConvertListOfIOInListOfIOR()
559 //=======================================================================
560 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
562 int nbSel = aList.Extent();
563 listIOR.length(nbSel);
565 SALOME_ListIteratorOfListIO It(aList);
566 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
567 ( SUIT_Session::session()->activeApplication()->activeStudy() );
568 if ( !appStudy ) return;
569 _PTR(Study) aStudy = appStudy->studyDS();
571 for (int i=0; It.More(); It.Next(), i++) {
572 Handle(SALOME_InteractiveObject) IObject = It.Value();
573 if (IObject->hasEntry()) {
574 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
575 _PTR(GenericAttribute) anAttr;
576 if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
577 _PTR(AttributeIOR) anIOR (anAttr);
578 //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
579 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
580 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
581 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
582 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
592 //=======================================================================
593 // function : ConvertIOinGEOMObject()
595 //=======================================================================
596 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
597 Standard_Boolean& theResult )
599 theResult = Standard_False;
600 GEOM::GEOM_Object_var aReturnObject;
601 if ( !theIO.IsNull() )
603 const char* anEntry = theIO->getEntry();
605 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
606 ( SUIT_Session::session()->activeApplication()->activeStudy() );
607 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
608 _PTR(Study) aStudy = appStudy->studyDS();
610 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
614 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
615 theResult = !CORBA::is_nil( aReturnObject );
618 return aReturnObject._retn();
622 //=======================================================================
623 // function : ConvertListOfIOInListOfGO()
625 //=======================================================================
626 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
627 GEOM::ListOfGO& theListGO,
628 const bool theShapesOnly )
630 int nbSel = theList.Extent();
631 theListGO.length( nbSel );
632 SALOME_ListIteratorOfListIO anIter( theList );
634 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
635 if ( !appStudy ) return;
636 _PTR(Study) aStudy = appStudy->studyDS();
639 for ( int i=0; anIter.More(); anIter.Next(), i++ )
641 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
642 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
646 GEOM::GEOM_Object_var aGeomObj =
647 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
648 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
649 theListGO[ j++ ] = aGeomObj;
653 theListGO.length( j );
656 //=================================================================================
657 // function : CreateArrowForLinearEdge()
658 // purpose : Create a cone topology to be used to display an arrow in the middle
659 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
660 //=================================================================================
661 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
663 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
664 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
667 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
668 Handle( V3d_View) view3d = vp3d->getView();
669 Standard_Real Width, Height;
670 view3d->Size(Width, Height);
671 const Standard_Real aHeight = (Width + Height) / 50.0;
674 Standard_Real first, last;
675 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
679 const Standard_Real param = (first+last) / 2.0;
680 gp_Pnt middleParamPoint;
682 curv->D1( param, middleParamPoint, V1);
683 if(V1.Magnitude() < Precision::Confusion())
686 /* Topology orientation not geom orientation */
687 if(tds.Orientation() == TopAbs_REVERSED)
690 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
691 const Standard_Real radius1 = aHeight / 5.0;
692 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
693 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
697 catch(Standard_Failure) {
698 // OCC failures are hard to catch in GUI.
699 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
700 // in SALOME environment : compilation error !
706 //=================================================================================
707 // function : VertexToPoint()
708 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
709 //=================================================================================
710 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
712 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
714 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
719 //=================================================================================
720 // function : GetBipointDxDyDz()
722 //=================================================================================
723 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
725 dx = P2.X() - P1.X();
726 dy = P2.Y() - P1.Y();
727 dz = P2.Z() - P1.Z();
732 //=================================================================================
733 // function : LinearEdgeExtremities()
734 // purpose : If S can be converted in a linear edge and if initial an final points
735 // : distance is sufficient, returns true else returns false.
736 // : Resulting points are respectively P1 and P2
737 //=================================================================================
738 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
740 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
742 BRepAdaptor_Curve curv(TopoDS::Edge(S));
743 if(curv.GetType() != GeomAbs_Line)
746 curv.D0(curv.FirstParameter(), P1);
747 curv.D0(curv.LastParameter(), P2);
749 if(P1.Distance(P2) <= Precision::Confusion())
756 //=======================================================================
757 // function : Parameter()
758 // purpose : return a parameter (float) from a dialog box
760 // avalue1 : is a float or integer used as a default value displayed
761 // aTitle1 : is the title for aValue1
762 // aTitle : is the main title
763 // bottom : maximum value to be entered
764 // top : minimum value to be entered
765 // decimals : number of decimals
766 //=======================================================================
767 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
769 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
770 aTitle, TRUE, 0, bottom, top, decimals);
771 int r = Dialog->exec();
773 if(r == QDialog::Accepted) {
775 X = Dialog->getValue();
778 res = Standard_False;
784 //=======================================================================
785 // function : SelectionByNameInDialogs()
786 // purpose : Called when user has entered a name of object in a LineEdit.
787 // : The selection is changed. Dialog box will receive the
788 // : corresponding signal to manage this event.
789 //=======================================================================
790 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
792 /* Find SObject with name in component GEOM */
793 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
794 if ( !appStudy ) return false;
795 _PTR(Study) ST = appStudy->studyDS();
797 std::vector<_PTR(SObject)> listSO;
798 listSO = ST->FindObjectByName(objectUserName.latin1(), "GEOM");
800 if(listSO.size() < 1) {
801 const QString caption = QObject::tr("GEOM_WRN_WARNING");
802 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
803 const QString button0 = QObject::tr("GEOM_BUT_OK");
804 SUIT_MessageBox::error1(aWidget, caption, text, button0);
807 /* More than one object with same name */
808 if(listSO.size() > 1) {
809 const QString caption = QObject::tr("GEOM_WRN_WARNING");
810 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
811 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
812 SUIT_MessageBox::error1(aWidget, caption, text, button0) ;
817 _PTR(SObject) theObj ( listSO[0] );
818 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
819 char* aCopyobjectUserName = CORBA::string_dup(objectUserName);
820 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
821 delete(aCopyobjectUserName);
823 /* Add as a selected object */
824 /* Clear any previous selection : */
825 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
826 // Sel->ClearIObjects(); //mzn
827 // Sel->AddIObject(SI); //mzn
832 //=======================================================================
833 // function : DefineDlgPosition()
834 // purpose : Define x and y the default position for a dialog box
835 //=======================================================================
836 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
838 /* Here the position is on the bottom right corner - 10 */
839 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
840 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
841 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
846 //=======================================================================
847 // function : GetDefaultName()
848 // purpose : Generates default names
849 //=======================================================================
850 QString GEOMBase::GetDefaultName(const QString& theOperation)
854 // collect all object names of GEOM component
855 SalomeApp_Study* appStudy =
856 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
857 if ( !appStudy ) return aName;
858 _PTR(Study) aStudy = appStudy->studyDS();
860 std::set<std::string> aSet;
861 _PTR(SComponent) aGeomCompo (aStudy->FindComponent("GEOM"));
863 _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeomCompo));
865 for (it->InitEx(true); it->More(); it->Next()) {
867 aSet.insert(obj->GetName());
871 // build a unique name
873 bool isUnique = false;
875 aName = theOperation + "_" + QString::number(++aNumber);
876 isUnique = (aSet.count(aName.latin1()) == 0);
883 //=======================================================================
884 // function : ShowErrorMessage()
885 // purpose : Shows message box with error code and comment
886 //=======================================================================
887 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
889 QString anErrorCode(theErrorCode);
890 QString aComment(theComment);
893 if (!anErrorCode.isEmpty())
894 aText.append("\n" + QObject::tr(anErrorCode));
895 if (!aComment.isEmpty())
896 aText.append("\n" + QString(theComment));
898 SUIT_MessageBox::error1( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
899 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
903 //=======================================================================
904 // function : GetObjectFromIOR()
905 // purpose : returns a GEOM_Object by given IOR (string)
906 //=======================================================================
907 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
909 GEOM::GEOM_Object_var anObject;
910 if ( theIOR == NULL || strlen( theIOR ) == 0 )
911 return anObject._retn(); // returning nil object
913 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
914 return anObject._retn();
917 //=======================================================================
918 // function : GetIORFromObject()
919 // purpose : returns IOR of a given GEOM_Object
920 //=======================================================================
921 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
923 if ( CORBA::is_nil( theObject ) )
926 return SalomeApp_Application::orb()->object_to_string( theObject );
929 //=======================================================================
930 // function : GetShape()
931 // purpose : returns a TopoDS_Shape stored in GEOM_Object
932 //=======================================================================
933 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
935 if ( !CORBA::is_nil( theObject ) )
937 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
938 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
940 theShape = aTopoDSShape;
947 //=======================================================================
948 // function : GetName()
949 // purpose : Get name of object
950 //=======================================================================
951 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
953 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
957 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
958 if ( strcmp(anIOR.in(), "") != 0 )
960 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( string( anIOR ) ) );
962 _PTR(GenericAttribute) anAttr;
964 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
966 _PTR(AttributeName) aNameAttr ( anAttr );
967 return QString( aNameAttr->Value().c_str() );
975 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
977 return !theObj->_is_nil() && theObj->IsShape();