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 "GEOM_Actor.h"
37 #include "SVTK_ViewModel.h"
38 #include "SVTK_ViewWindow.h"
39 #include "OCCViewer_ViewPort3d.h"
40 #include "OCCViewer_ViewModel.h"
41 #include "OCCViewer_ViewWindow.h"
43 #include "SALOME_ListIO.hxx"
44 #include "SALOME_ListIteratorOfListIO.hxx"
46 #include "SUIT_Desktop.h"
47 #include "SUIT_Session.h"
48 #include "SUIT_ViewManager.h"
49 #include "SUIT_ViewWindow.h"
50 #include "SUIT_MessageBox.h"
51 #include "SalomeApp_Application.h"
52 #include "SalomeApp_Study.h"
54 // // Open CASCADE Includes
55 #include <BRep_Tool.hxx>
56 #include <BRepAdaptor_Curve.hxx>
57 #include <BRepAdaptor_Surface.hxx>
58 #include <BRepPrimAPI_MakeCone.hxx>
60 #include <AIS_ListIteratorOfListOfInteractive.hxx>
61 #include <AIS_ListOfInteractive.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
67 #include <Precision.hxx>
69 #include <vtkRenderer.h>
76 //=====================================================================================
77 // function : GetShapeFromIOR()
78 // purpose : exist also as static method !
79 //=====================================================================================
80 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
83 if(IOR.trimmed().isEmpty())
86 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
87 if(CORBA::is_nil(obj))
89 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
90 if (GeomObject->_is_nil())
93 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
98 //=====================================================================================
99 // function : GetIndex()
100 // purpose : Get the index of a sub shape in a main shape : index start at 1
101 //=====================================================================================
102 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
104 if(shape.IsNull() || subshape.IsNull())
107 TopTools_IndexedMapOfShape anIndices;
108 TopExp::MapShapes(shape, anIndices);
109 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
115 //=======================================================================
116 // function : GetTopoFromSelection()
117 // purpose : Define tds from a single selection and retuen true
118 //=======================================================================
119 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
121 if(aList.Extent() != 1)
124 Handle(SALOME_InteractiveObject) IO = aList.First();
127 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
128 if ( !appStudy ) return false;
129 _PTR(Study) aStudy = appStudy->studyDS();
131 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
132 _PTR(GenericAttribute) anAttr;
134 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
135 _PTR(AttributeIOR) anIOR ( anAttr );
136 tds = GetShapeFromIOR(anIOR->Value().c_str());
148 //=======================================================================
149 // function : GetNameOfSelectedIObjects()
150 // purpose : Define the name geom++ or other name of mono or multi sel.
151 //=======================================================================
152 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
154 const bool theShapesOnly )
156 if ( !theShapesOnly )
158 int nbSel = aList.Extent();
161 Handle(SALOME_InteractiveObject) anIObj = aList.First();
162 if(anIObj->hasEntry()) {
163 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
164 if ( !appStudy ) return nbSel;
165 _PTR(Study) aStudy = appStudy->studyDS();
167 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
169 _PTR(GenericAttribute) anAttr;
171 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
173 _PTR(AttributeName) aNameAttr ( anAttr );
174 theName = aNameAttr->Value().c_str();
179 theName = QObject::tr("%1_objects").arg(nbSel);
185 GEOM::ListOfGO anObjs;
186 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
187 if ( anObjs.length() == 1 ) {
188 theName = GetName( anObjs[ 0 ] );
191 theName = QString( "%1_objects" ).arg( anObjs.length() );
193 return anObjs.length();
198 //=================================================================================
199 // function : GetShapeTypeString()
200 // purpose : for a single shape
201 //=================================================================================
202 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
204 if(aShape.IsNull()) {
205 aTypeString = "aNullShape";
208 switch(aShape.ShapeType())
210 case TopAbs_COMPOUND:
212 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND").toStdString().c_str());
215 case TopAbs_COMPSOLID:
217 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID").toStdString().c_str()) ;
222 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID").toStdString().c_str()) ;
227 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL").toStdString().c_str()) ;
232 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
233 if(surf.GetType() == GeomAbs_Plane) {
234 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE").toStdString().c_str());
237 else if(surf.GetType() == GeomAbs_Cylinder) {
238 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER").toStdString().c_str());
241 else if(surf.GetType() == GeomAbs_Sphere) {
242 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE").toStdString().c_str());
245 else if(surf.GetType() == GeomAbs_Torus) {
246 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS").toStdString().c_str());
249 else if(surf.GetType() == GeomAbs_Cone) {
250 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE").toStdString().c_str());
254 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE").toStdString().c_str());
260 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE").toStdString().c_str());
265 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
266 if(curv.GetType() == GeomAbs_Line) {
267 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
268 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE").toStdString().c_str());
270 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toStdString().c_str());
273 else if(curv.GetType() == GeomAbs_Circle) {
275 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE").toStdString().c_str());
277 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC").toStdString().c_str());
281 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toStdString().c_str());
287 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX").toStdString().c_str());
292 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE").toStdString().c_str());
300 //=======================================================================
301 // function : ConvertIORinGEOMAISShape()
303 //=======================================================================
304 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
306 Handle(GEOM_AISShape) resultShape;
309 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
310 if ( !appStudy ) return resultShape;
311 _PTR(Study) aStudy = appStudy->studyDS();
313 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
317 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
319 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
320 while ( it.hasNext() ) {
321 SUIT_ViewWindow* aVW = it.next();
322 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
323 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
325 AIS_ListOfInteractive List;
326 ic->DisplayedObjects(List);
327 AIS_ListOfInteractive List1;
328 ic->ObjectsInCollector(List1);
331 AIS_ListIteratorOfListOfInteractive ite(List);
333 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
334 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
336 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
337 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
338 if(!onlyInActiveView ||
339 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
355 //=======================================================================
356 // function : ConvertIORinGEOMActor()
358 //=======================================================================
359 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
363 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
364 if ( !appStudy ) return GEOM_Actor::New();
365 _PTR(Study) aStudy = appStudy->studyDS();
367 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
369 return GEOM_Actor::New();
371 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
373 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
374 while ( it.hasNext() ) {
375 SUIT_ViewWindow* aVW = it.next();
376 if (aVW && aVW->getViewManager()->getType() == SVTK_Viewer::Type()) {
377 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( aVW );
378 if( !aVTKViewWindow )
380 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
381 vtkActorCollection* theActors = Renderer->GetActors();
382 theActors->InitTraversal();
383 vtkActor *ac = theActors->GetNextActor();
385 if( ac->IsA("GEOM_Actor")) {
386 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
387 if(anActor->hasIO()) {
388 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
389 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
390 if(!onlyInActiveView ||
391 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
398 ac = theActors->GetNextActor();
403 return GEOM_Actor::New();
406 //=======================================================================
407 // function : GetAIS()
409 //=======================================================================
410 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
411 const bool isOnlyInActiveView )
413 if ( theIO.IsNull() || !theIO->hasEntry() )
414 return Handle(AIS_InteractiveObject)();
416 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
418 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
419 while ( it.hasNext() ) {
420 SUIT_ViewWindow* aVW = it.next();
421 if (!aVW || aVW->getViewManager()->getType() != OCCViewer_Viewer::Type())
423 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
425 AIS_ListOfInteractive aList;
426 anIC->DisplayedObjects( aList );
427 anIC->ObjectsInCollector( aList );
429 AIS_ListIteratorOfListOfInteractive anIter( aList );
430 for ( ; anIter.More(); anIter.Next() )
432 Handle(SALOME_InteractiveObject) anObj =
433 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
435 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
437 if( isOnlyInActiveView )
439 if ( aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
440 return anIter.Value();
443 return anIter.Value();
448 return Handle(AIS_InteractiveObject)();
452 //=======================================================================
453 // function : ConvertIOinGEOMAISShape()
455 //=======================================================================
456 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
458 Handle(GEOM_AISShape) res;
460 if ( !IO->hasEntry() )
466 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
468 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
469 while ( it.hasNext() ) {
470 SUIT_ViewWindow* aVW = it.next();
471 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
472 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
474 AIS_ListOfInteractive List;
475 ic->DisplayedObjects(List);
476 AIS_ListOfInteractive List1;
477 ic->ObjectsInCollector(List1);
480 AIS_ListIteratorOfListOfInteractive ite(List);
483 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
485 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
488 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
492 if(aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
515 //=======================================================================
516 // function : ConvertIOinGEOMShape()
518 //=======================================================================
519 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
521 GEOM::GEOM_Object_var aShape;
526 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
527 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
528 _PTR(Study) aStudy = appStudy->studyDS();
530 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
531 _PTR(GenericAttribute) anAttr;
533 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
534 _PTR(AttributeIOR) anIOR ( anAttr );
535 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
536 if(!CORBA::is_nil(aShape))
538 return aShape._retn();
542 return GEOM::GEOM_Object::_nil();
546 //=======================================================================
547 // function : ConvertListOfIOInListOfIOR()
549 //=======================================================================
550 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
552 int nbSel = aList.Extent();
553 listIOR.length(nbSel);
555 SALOME_ListIteratorOfListIO It(aList);
556 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
557 ( SUIT_Session::session()->activeApplication()->activeStudy() );
558 if ( !appStudy ) return;
559 _PTR(Study) aStudy = appStudy->studyDS();
561 for (int i=0; It.More(); It.Next(), i++) {
562 Handle(SALOME_InteractiveObject) IObject = It.Value();
563 if (IObject->hasEntry()) {
564 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
565 _PTR(GenericAttribute) anAttr;
566 if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
567 _PTR(AttributeIOR) anIOR (anAttr);
568 //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
569 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
570 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
571 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
572 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
582 //=======================================================================
583 // function : ConvertIOinGEOMObject()
585 //=======================================================================
586 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
587 Standard_Boolean& theResult )
589 theResult = Standard_False;
590 GEOM::GEOM_Object_var aReturnObject;
591 if ( !theIO.IsNull() )
593 const char* anEntry = theIO->getEntry();
595 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
596 ( SUIT_Session::session()->activeApplication()->activeStudy() );
597 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
598 _PTR(Study) aStudy = appStudy->studyDS();
600 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
604 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
605 theResult = !CORBA::is_nil( aReturnObject );
608 return aReturnObject._retn();
612 //=======================================================================
613 // function : ConvertListOfIOInListOfGO()
615 //=======================================================================
616 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
617 GEOM::ListOfGO& theListGO,
618 const bool theShapesOnly )
620 int nbSel = theList.Extent();
621 theListGO.length( nbSel );
622 SALOME_ListIteratorOfListIO anIter( theList );
624 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
625 if ( !appStudy ) return;
626 _PTR(Study) aStudy = appStudy->studyDS();
629 for ( int i=0; anIter.More(); anIter.Next(), i++ )
631 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
632 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
636 GEOM::GEOM_Object_var aGeomObj =
637 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
638 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
639 theListGO[ j++ ] = aGeomObj;
643 theListGO.length( j );
646 //=================================================================================
647 // function : CreateArrowForLinearEdge()
648 // purpose : Create a cone topology to be used to display an arrow in the middle
649 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
650 //=================================================================================
651 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
653 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
654 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
657 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
658 Handle( V3d_View) view3d = vp3d->getView();
659 Standard_Real Width, Height;
660 view3d->Size(Width, Height);
661 const Standard_Real aHeight = (Width + Height) / 50.0;
664 Standard_Real first, last;
665 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
669 const Standard_Real param = (first+last) / 2.0;
670 gp_Pnt middleParamPoint;
672 curv->D1( param, middleParamPoint, V1);
673 if(V1.Magnitude() < Precision::Confusion())
676 /* Topology orientation not geom orientation */
677 if(tds.Orientation() == TopAbs_REVERSED)
680 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
681 const Standard_Real radius1 = aHeight / 5.0;
682 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
683 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
687 catch(Standard_Failure) {
688 // OCC failures are hard to catch in GUI.
689 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
690 // in SALOME environment : compilation error !
696 //=================================================================================
697 // function : VertexToPoint()
698 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
699 //=================================================================================
700 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
702 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
704 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
709 //=================================================================================
710 // function : GetBipointDxDyDz()
712 //=================================================================================
713 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
715 dx = P2.X() - P1.X();
716 dy = P2.Y() - P1.Y();
717 dz = P2.Z() - P1.Z();
722 //=================================================================================
723 // function : LinearEdgeExtremities()
724 // purpose : If S can be converted in a linear edge and if initial an final points
725 // : distance is sufficient, returns true else returns false.
726 // : Resulting points are respectively P1 and P2
727 //=================================================================================
728 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
730 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
732 BRepAdaptor_Curve curv(TopoDS::Edge(S));
733 if(curv.GetType() != GeomAbs_Line)
736 curv.D0(curv.FirstParameter(), P1);
737 curv.D0(curv.LastParameter(), P2);
739 if(P1.Distance(P2) <= Precision::Confusion())
746 //=======================================================================
747 // function : Parameter()
748 // purpose : return a parameter (float) from a dialog box
750 // avalue1 : is a float or integer used as a default value displayed
751 // aTitle1 : is the title for aValue1
752 // aTitle : is the main title
753 // bottom : maximum value to be entered
754 // top : minimum value to be entered
755 // decimals : number of decimals
756 //=======================================================================
757 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
759 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
760 aTitle, TRUE, 0, bottom, top, decimals);
761 int r = Dialog->exec();
763 if(r == QDialog::Accepted) {
765 X = Dialog->getValue();
768 res = Standard_False;
774 //=======================================================================
775 // function : SelectionByNameInDialogs()
776 // purpose : Called when user has entered a name of object in a LineEdit.
777 // : The selection is changed. Dialog box will receive the
778 // : corresponding signal to manage this event.
779 //=======================================================================
780 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
782 /* Find SObject with name in component GEOM */
783 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
784 if ( !appStudy ) return false;
785 _PTR(Study) ST = appStudy->studyDS();
787 std::vector<_PTR(SObject)> listSO;
788 listSO = ST->FindObjectByName(objectUserName.toStdString(), "GEOM");
790 if(listSO.size() < 1) {
791 const QString caption = QObject::tr("GEOM_WRN_WARNING");
792 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
793 const QString button0 = QObject::tr("GEOM_BUT_OK");
794 SUIT_MessageBox::critical(aWidget, caption, text, button0);
797 /* More than one object with same name */
798 if(listSO.size() > 1) {
799 const QString caption = QObject::tr("GEOM_WRN_WARNING");
800 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
801 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
802 SUIT_MessageBox::critical(aWidget, caption, text, button0) ;
807 _PTR(SObject) theObj ( listSO[0] );
808 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
809 char* aCopyobjectUserName = CORBA::string_dup(objectUserName.toStdString().c_str());
810 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
811 delete(aCopyobjectUserName);
813 /* Add as a selected object */
814 /* Clear any previous selection : */
815 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
816 // Sel->ClearIObjects(); //mzn
817 // Sel->AddIObject(SI); //mzn
822 //=======================================================================
823 // function : DefineDlgPosition()
824 // purpose : Define x and y the default position for a dialog box
825 //=======================================================================
826 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
828 /* Here the position is on the bottom right corner - 10 */
829 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
830 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
831 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
836 //=======================================================================
837 // function : GetDefaultName()
838 // purpose : Generates default names
839 //=======================================================================
840 QString GEOMBase::GetDefaultName(const QString& theOperation)
844 // collect all object names of GEOM component
845 SalomeApp_Study* appStudy =
846 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
847 if ( !appStudy ) return aName;
848 _PTR(Study) aStudy = appStudy->studyDS();
850 std::set<std::string> aSet;
851 _PTR(SComponent) aGeomCompo (aStudy->FindComponent("GEOM"));
853 _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeomCompo));
855 for (it->InitEx(true); it->More(); it->Next()) {
857 aSet.insert(obj->GetName());
861 // build a unique name
863 bool isUnique = false;
865 aName = theOperation + "_" + QString::number(++aNumber);
866 isUnique = (aSet.count(aName.toStdString()) == 0);
873 //=======================================================================
874 // function : ShowErrorMessage()
875 // purpose : Shows message box with error code and comment
876 //=======================================================================
877 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
879 QString anErrorCode(theErrorCode);
880 QString aComment(theComment);
883 if (!anErrorCode.isEmpty())
884 aText.append("\n" + QObject::tr(anErrorCode.toStdString().c_str()));
885 if (!aComment.isEmpty())
886 aText.append("\n" + QString(theComment));
888 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
889 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
893 //=======================================================================
894 // function : GetObjectFromIOR()
895 // purpose : returns a GEOM_Object by given IOR (string)
896 //=======================================================================
897 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
899 GEOM::GEOM_Object_var anObject;
900 if ( theIOR == NULL || strlen( theIOR ) == 0 )
901 return anObject._retn(); // returning nil object
903 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
904 return anObject._retn();
907 //=======================================================================
908 // function : GetIORFromObject()
909 // purpose : returns IOR of a given GEOM_Object
910 //=======================================================================
911 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
913 if ( CORBA::is_nil( theObject ) )
916 return SalomeApp_Application::orb()->object_to_string( theObject );
919 //=======================================================================
920 // function : GetShape()
921 // purpose : returns a TopoDS_Shape stored in GEOM_Object
922 //=======================================================================
923 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
925 if ( !CORBA::is_nil( theObject ) )
927 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
928 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
930 theShape = aTopoDSShape;
937 //=======================================================================
938 // function : GetName()
939 // purpose : Get name of object
940 //=======================================================================
941 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
943 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
947 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
948 if ( strcmp(anIOR.in(), "") != 0 )
950 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( string( anIOR ) ) );
952 _PTR(GenericAttribute) anAttr;
954 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
956 _PTR(AttributeName) aNameAttr ( anAttr );
957 return QString( aNameAttr->Value().c_str() );
965 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
967 return !theObj->_is_nil() && theObj->IsShape();