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
22 // File : GEOMBase.cxx
23 // Author : Damien COQUERET, Open CASCADE S.A.S.
28 #include "GEOMBase_aParameterDlg.h"
30 #include <GeometryGUI.h>
31 #include <GEOM_Client.hxx>
34 #include <GEOM_Actor.h>
35 #include <SVTK_ViewModel.h>
36 #include <SVTK_ViewWindow.h>
37 #include <OCCViewer_ViewPort3d.h>
38 #include <OCCViewer_ViewModel.h>
39 #include <OCCViewer_ViewWindow.h>
41 #include <SALOME_ListIO.hxx>
42 #include <SALOME_ListIteratorOfListIO.hxx>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_ViewWindow.h>
48 #include <SUIT_MessageBox.h>
49 #include <SalomeApp_Application.h>
50 #include <SalomeApp_Study.h>
52 // // Open CASCADE Includes
53 #include <BRep_Tool.hxx>
54 #include <BRepAdaptor_Curve.hxx>
55 #include <BRepAdaptor_Surface.hxx>
56 #include <BRepPrimAPI_MakeCone.hxx>
58 #include <AIS_ListIteratorOfListOfInteractive.hxx>
59 #include <AIS_ListOfInteractive.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
65 #include <Precision.hxx>
67 #include <vtkRenderer.h>
74 //=====================================================================================
75 // function : GetShapeFromIOR()
76 // purpose : exist also as static method !
77 //=====================================================================================
78 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
81 if(IOR.trimmed().isEmpty())
84 CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
85 if(CORBA::is_nil(obj))
87 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
88 if (GeomObject->_is_nil())
91 result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
96 //=====================================================================================
97 // function : GetIndex()
98 // purpose : Get the index of a sub shape in a main shape : index start at 1
99 //=====================================================================================
100 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
102 if(shape.IsNull() || subshape.IsNull())
105 TopTools_IndexedMapOfShape anIndices;
106 TopExp::MapShapes(shape, anIndices);
107 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
113 //=======================================================================
114 // function : GetTopoFromSelection()
115 // purpose : Define tds from a single selection and retuen true
116 //=======================================================================
117 bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
119 if(aList.Extent() != 1)
122 Handle(SALOME_InteractiveObject) IO = aList.First();
125 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
126 if ( !appStudy ) return false;
127 _PTR(Study) aStudy = appStudy->studyDS();
129 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
130 _PTR(GenericAttribute) anAttr;
132 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
133 _PTR(AttributeIOR) anIOR ( anAttr );
134 tds = GetShapeFromIOR(anIOR->Value().c_str());
146 //=======================================================================
147 // function : GetNameOfSelectedIObjects()
148 // purpose : Define the name geom++ or other name of mono or multi sel.
149 //=======================================================================
150 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
152 const bool theShapesOnly )
154 if ( !theShapesOnly )
156 int nbSel = aList.Extent();
159 Handle(SALOME_InteractiveObject) anIObj = aList.First();
160 if(anIObj->hasEntry()) {
161 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
162 if ( !appStudy ) return nbSel;
163 _PTR(Study) aStudy = appStudy->studyDS();
165 _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
167 _PTR(GenericAttribute) anAttr;
169 if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
171 _PTR(AttributeName) aNameAttr ( anAttr );
172 theName = aNameAttr->Value().c_str();
177 theName = QObject::tr("%1_objects").arg(nbSel);
183 GEOM::ListOfGO anObjs;
184 ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
185 if ( anObjs.length() == 1 ) {
186 theName = GetName( anObjs[ 0 ] );
189 theName = QString( "%1_objects" ).arg( anObjs.length() );
191 return anObjs.length();
196 //=================================================================================
197 // function : GetShapeTypeString()
198 // purpose : for a single shape
199 //=================================================================================
200 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
202 if(aShape.IsNull()) {
203 aTypeString = "aNullShape";
206 switch(aShape.ShapeType())
208 case TopAbs_COMPOUND:
210 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND").toLatin1().constData());
213 case TopAbs_COMPSOLID:
215 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID").toLatin1().constData()) ;
220 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID").toLatin1().constData()) ;
225 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL").toLatin1().constData()) ;
230 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
231 if(surf.GetType() == GeomAbs_Plane) {
232 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE").toLatin1().constData());
235 else if(surf.GetType() == GeomAbs_Cylinder) {
236 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER").toLatin1().constData());
239 else if(surf.GetType() == GeomAbs_Sphere) {
240 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE").toLatin1().constData());
243 else if(surf.GetType() == GeomAbs_Torus) {
244 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS").toLatin1().constData());
247 else if(surf.GetType() == GeomAbs_Cone) {
248 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE").toLatin1().constData());
252 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE").toLatin1().constData());
258 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE").toLatin1().constData());
263 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
264 if(curv.GetType() == GeomAbs_Line) {
265 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
266 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE").toLatin1().constData());
268 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
271 else if(curv.GetType() == GeomAbs_Circle) {
273 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE").toLatin1().constData());
275 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC").toLatin1().constData());
279 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
285 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX").toLatin1().constData());
290 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE").toLatin1().constData());
298 //=======================================================================
299 // function : ConvertIORinGEOMAISShape()
301 //=======================================================================
302 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
304 Handle(GEOM_AISShape) resultShape;
307 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
308 if ( !appStudy ) return resultShape;
309 _PTR(Study) aStudy = appStudy->studyDS();
311 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
315 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
317 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
318 while ( it.hasNext() ) {
319 SUIT_ViewWindow* aVW = it.next();
320 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
321 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
323 AIS_ListOfInteractive List;
324 ic->DisplayedObjects(List);
325 AIS_ListOfInteractive List1;
326 ic->ObjectsInCollector(List1);
329 AIS_ListIteratorOfListOfInteractive ite(List);
331 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
332 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
334 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
335 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
336 if(!onlyInActiveView ||
337 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
353 //=======================================================================
354 // function : ConvertIORinGEOMActor()
356 //=======================================================================
357 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
361 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
362 if ( !appStudy ) return GEOM_Actor::New();
363 _PTR(Study) aStudy = appStudy->studyDS();
365 _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
367 return GEOM_Actor::New();
369 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
371 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
372 while ( it.hasNext() ) {
373 SUIT_ViewWindow* aVW = it.next();
374 if (aVW && aVW->getViewManager()->getType() == SVTK_Viewer::Type()) {
375 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( aVW );
376 if( !aVTKViewWindow )
378 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
379 vtkActorCollection* theActors = Renderer->GetActors();
380 theActors->InitTraversal();
381 vtkActor *ac = theActors->GetNextActor();
383 if( ac->IsA("GEOM_Actor")) {
384 GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
385 if(anActor->hasIO()) {
386 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
387 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
388 if(!onlyInActiveView ||
389 aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
396 ac = theActors->GetNextActor();
401 return GEOM_Actor::New();
404 //=======================================================================
405 // function : GetAIS()
407 //=======================================================================
408 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
409 const bool isOnlyInActiveView )
411 if ( theIO.IsNull() || !theIO->hasEntry() )
412 return Handle(AIS_InteractiveObject)();
414 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
416 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
417 while ( it.hasNext() ) {
418 SUIT_ViewWindow* aVW = it.next();
419 if (!aVW || aVW->getViewManager()->getType() != OCCViewer_Viewer::Type())
421 Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
423 AIS_ListOfInteractive aList;
424 anIC->DisplayedObjects( aList );
425 anIC->ObjectsInCollector( aList );
427 AIS_ListIteratorOfListOfInteractive anIter( aList );
428 for ( ; anIter.More(); anIter.Next() )
430 Handle(SALOME_InteractiveObject) anObj =
431 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
433 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
435 if( isOnlyInActiveView )
437 if ( aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
438 return anIter.Value();
441 return anIter.Value();
446 return Handle(AIS_InteractiveObject)();
450 //=======================================================================
451 // function : ConvertIOinGEOMAISShape()
453 //=======================================================================
454 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
456 Handle(GEOM_AISShape) res;
458 if ( !IO->hasEntry() )
464 QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
466 QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
467 while ( it.hasNext() ) {
468 SUIT_ViewWindow* aVW = it.next();
469 if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
470 Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
472 AIS_ListOfInteractive List;
473 ic->DisplayedObjects(List);
474 AIS_ListOfInteractive List1;
475 ic->ObjectsInCollector(List1);
478 AIS_ListIteratorOfListOfInteractive ite(List);
481 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
483 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
486 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
490 if(aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
513 //=======================================================================
514 // function : ConvertIOinGEOMShape()
516 //=======================================================================
517 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
519 GEOM::GEOM_Object_var aShape;
524 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
525 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
526 _PTR(Study) aStudy = appStudy->studyDS();
528 _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
529 _PTR(GenericAttribute) anAttr;
531 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
532 _PTR(AttributeIOR) anIOR ( anAttr );
533 aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
534 if(!CORBA::is_nil(aShape))
536 return aShape._retn();
540 return GEOM::GEOM_Object::_nil();
544 //=======================================================================
545 // function : ConvertListOfIOInListOfIOR()
547 //=======================================================================
548 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
550 int nbSel = aList.Extent();
551 listIOR.length(nbSel);
553 SALOME_ListIteratorOfListIO It(aList);
554 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
555 ( SUIT_Session::session()->activeApplication()->activeStudy() );
556 if ( !appStudy ) return;
557 _PTR(Study) aStudy = appStudy->studyDS();
559 for (int i=0; It.More(); It.Next(), i++) {
560 Handle(SALOME_InteractiveObject) IObject = It.Value();
561 if (IObject->hasEntry()) {
562 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
563 _PTR(GenericAttribute) anAttr;
564 if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
565 _PTR(AttributeIOR) anIOR (anAttr);
566 //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
567 // (aStudy.get())->ConvertIORToObject(anIOR->Value());
568 CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
569 if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
570 listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
580 //=======================================================================
581 // function : ConvertIOinGEOMObject()
583 //=======================================================================
584 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
585 Standard_Boolean& theResult )
587 theResult = Standard_False;
588 GEOM::GEOM_Object_var aReturnObject;
589 if ( !theIO.IsNull() )
591 const char* anEntry = theIO->getEntry();
593 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
594 ( SUIT_Session::session()->activeApplication()->activeStudy() );
595 if ( !appStudy ) return GEOM::GEOM_Object::_nil();
596 _PTR(Study) aStudy = appStudy->studyDS();
598 _PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) );
602 aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
603 theResult = !CORBA::is_nil( aReturnObject );
606 return aReturnObject._retn();
610 //=======================================================================
611 // function : ConvertListOfIOInListOfGO()
613 //=======================================================================
614 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
615 GEOM::ListOfGO& theListGO,
616 const bool theShapesOnly )
618 int nbSel = theList.Extent();
619 theListGO.length( nbSel );
620 SALOME_ListIteratorOfListIO anIter( theList );
622 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
623 if ( !appStudy ) return;
624 _PTR(Study) aStudy = appStudy->studyDS();
627 for ( int i=0; anIter.More(); anIter.Next(), i++ )
629 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
630 _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
634 GEOM::GEOM_Object_var aGeomObj =
635 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
636 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
637 theListGO[ j++ ] = aGeomObj;
641 theListGO.length( j );
644 //=================================================================================
645 // function : CreateArrowForLinearEdge()
646 // purpose : Create a cone topology to be used to display an arrow in the middle
647 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
648 //=================================================================================
649 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
651 if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
652 != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
655 OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
656 Handle( V3d_View) view3d = vp3d->getView();
657 Standard_Real Width, Height;
658 view3d->Size(Width, Height);
659 const Standard_Real aHeight = (Width + Height) / 50.0;
662 Standard_Real first, last;
663 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
667 const Standard_Real param = (first+last) / 2.0;
668 gp_Pnt middleParamPoint;
670 curv->D1( param, middleParamPoint, V1);
671 if(V1.Magnitude() < Precision::Confusion())
674 /* Topology orientation not geom orientation */
675 if(tds.Orientation() == TopAbs_REVERSED)
678 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
679 const Standard_Real radius1 = aHeight / 5.0;
680 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
681 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
685 catch(Standard_Failure) {
686 // OCC failures are hard to catch in GUI.
687 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
688 // in SALOME environment : compilation error !
694 //=================================================================================
695 // function : VertexToPoint()
696 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
697 //=================================================================================
698 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
700 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
702 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
707 //=================================================================================
708 // function : GetBipointDxDyDz()
710 //=================================================================================
711 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
713 dx = P2.X() - P1.X();
714 dy = P2.Y() - P1.Y();
715 dz = P2.Z() - P1.Z();
720 //=================================================================================
721 // function : LinearEdgeExtremities()
722 // purpose : If S can be converted in a linear edge and if initial an final points
723 // : distance is sufficient, returns true else returns false.
724 // : Resulting points are respectively P1 and P2
725 //=================================================================================
726 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
728 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
730 BRepAdaptor_Curve curv(TopoDS::Edge(S));
731 if(curv.GetType() != GeomAbs_Line)
734 curv.D0(curv.FirstParameter(), P1);
735 curv.D0(curv.LastParameter(), P2);
737 if(P1.Distance(P2) <= Precision::Confusion())
744 //=======================================================================
745 // function : Parameter()
746 // purpose : return a parameter (float) from a dialog box
748 // avalue1 : is a float or integer used as a default value displayed
749 // aTitle1 : is the title for aValue1
750 // aTitle : is the main title
751 // bottom : maximum value to be entered
752 // top : minimum value to be entered
753 // decimals : number of decimals
754 //=======================================================================
755 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
757 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, SUIT_Session::session()->activeApplication()->desktop(),
758 aTitle, TRUE, 0, bottom, top, decimals);
759 int r = Dialog->exec();
761 if(r == QDialog::Accepted) {
763 X = Dialog->getValue();
766 res = Standard_False;
772 //=======================================================================
773 // function : SelectionByNameInDialogs()
774 // purpose : Called when user has entered a name of object in a LineEdit.
775 // : The selection is changed. Dialog box will receive the
776 // : corresponding signal to manage this event.
777 //=======================================================================
778 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
780 /* Find SObject with name in component GEOM */
781 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
782 if ( !appStudy ) return false;
783 _PTR(Study) ST = appStudy->studyDS();
785 std::vector<_PTR(SObject)> listSO;
786 listSO = ST->FindObjectByName(objectUserName.toStdString(), "GEOM");
788 if(listSO.size() < 1) {
789 const QString caption = QObject::tr("GEOM_WRN_WARNING");
790 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
791 const QString button0 = QObject::tr("GEOM_BUT_OK");
792 SUIT_MessageBox::critical(aWidget, caption, text, button0);
795 /* More than one object with same name */
796 if(listSO.size() > 1) {
797 const QString caption = QObject::tr("GEOM_WRN_WARNING");
798 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
799 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
800 SUIT_MessageBox::critical(aWidget, caption, text, button0) ;
805 _PTR(SObject) theObj ( listSO[0] );
806 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
807 char* aCopyobjectUserName = CORBA::string_dup(objectUserName.toLatin1().constData());
808 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
809 delete(aCopyobjectUserName);
811 /* Add as a selected object */
812 /* Clear any previous selection : */
813 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
814 // Sel->ClearIObjects(); //mzn
815 // Sel->AddIObject(SI); //mzn
820 //=======================================================================
821 // function : DefineDlgPosition()
822 // purpose : Define x and y the default position for a dialog box
823 //=======================================================================
824 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
826 /* Here the position is on the bottom right corner - 10 */
827 SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
828 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
829 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
834 //=======================================================================
835 // function : GetDefaultName()
836 // purpose : Generates default names
837 //=======================================================================
838 QString GEOMBase::GetDefaultName(const QString& theOperation)
842 // collect all object names of GEOM component
843 SalomeApp_Study* appStudy =
844 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
845 if ( !appStudy ) return aName;
846 _PTR(Study) aStudy = appStudy->studyDS();
848 std::set<std::string> aSet;
849 _PTR(SComponent) aGeomCompo (aStudy->FindComponent("GEOM"));
851 _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeomCompo));
853 for (it->InitEx(true); it->More(); it->Next()) {
855 aSet.insert(obj->GetName());
859 // build a unique name
861 bool isUnique = false;
863 aName = theOperation + "_" + QString::number(++aNumber);
864 isUnique = (aSet.count(aName.toStdString()) == 0);
871 //=======================================================================
872 // function : ShowErrorMessage()
873 // purpose : Shows message box with error code and comment
874 //=======================================================================
875 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
877 QString anErrorCode(theErrorCode);
878 QString aComment(theComment);
881 if (!anErrorCode.isEmpty())
882 aText.append("\n" + QObject::tr(anErrorCode.toLatin1().constData()));
883 if (!aComment.isEmpty())
884 aText.append("\n" + QString(theComment));
886 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
887 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
891 //=======================================================================
892 // function : GetObjectFromIOR()
893 // purpose : returns a GEOM_Object by given IOR (string)
894 //=======================================================================
895 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
897 GEOM::GEOM_Object_var anObject;
898 if ( theIOR == NULL || strlen( theIOR ) == 0 )
899 return anObject._retn(); // returning nil object
901 anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
902 return anObject._retn();
905 //=======================================================================
906 // function : GetIORFromObject()
907 // purpose : returns IOR of a given GEOM_Object
908 //=======================================================================
909 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
911 if ( CORBA::is_nil( theObject ) )
914 return SalomeApp_Application::orb()->object_to_string( theObject );
917 //=======================================================================
918 // function : GetShape()
919 // purpose : returns a TopoDS_Shape stored in GEOM_Object
920 //=======================================================================
921 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
923 if ( !CORBA::is_nil( theObject ) )
925 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObject );
926 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
928 theShape = aTopoDSShape;
935 //=======================================================================
936 // function : GetName()
937 // purpose : Get name of object
938 //=======================================================================
939 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
941 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
945 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
946 if ( strcmp(anIOR.in(), "") != 0 )
948 _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( string( anIOR ) ) );
950 _PTR(GenericAttribute) anAttr;
952 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
954 _PTR(AttributeName) aNameAttr ( anAttr );
955 return QString( aNameAttr->Value().c_str() );
963 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
965 return !theObj->_is_nil() && theObj->IsShape();