1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOMBase.cxx
25 // Author : Damien COQUERET
30 #include "GeometryGUI.h"
31 #include "GEOMBase_aParameterDlg.h"
34 #include "Utils_ORB_INIT.hxx"
35 #include "Utils_SINGLETON.hxx"
37 #include "QAD_Config.h"
38 #include "QAD_Desktop.h"
39 #include "QAD_RightFrame.h"
40 #include "QAD_MessageBox.h"
41 #include "QAD_Resource.h"
42 #include "QAD_MessageBox.h"
43 #include "SALOME_Selection.h"
45 #include "GEOM_AssemblyBuilder.h"
46 #include "GEOM_Actor.h"
47 #include "VTKViewer_ViewFrame.h"
48 #include "VTKViewer_RenderWindowInteractor.h"
49 #include "OCCViewer_ViewPort3d.h"
50 #include "OCCViewer_Viewer3d.h"
51 #include "OCCViewer_ViewFrame.h"
53 #include "SALOME_ListIteratorOfListIO.hxx"
54 #include "GEOM_AISTrihedron.hxx"
55 #include "SALOMEGUI_ImportOperation.h"
56 #include "SALOMEGUI_NameDlg.h"
58 // // Open CASCADE Includes
59 #include <BRep_Tool.hxx>
60 #include <BRepAdaptor_Curve.hxx>
61 #include <BRepAdaptor_Surface.hxx>
62 #include <BRepPrimAPI_MakeCone.hxx>
64 #include <Geom_Circle.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <AIS_ListOfInteractive.hxx>
70 #include <TopExp_Explorer.hxx>
71 #include <TopoDS_Iterator.hxx>
72 #include <TopoDS_Compound.hxx>
73 #include <TopTools_MapOfShape.hxx>
74 #include <TopTools_ListIteratorOfListOfShape.hxx>
75 #include <TopTools_IndexedMapOfShape.hxx>
77 #include <Precision.hxx>
79 #include <vtkRenderer.h>
80 #include <qvaluelist.h>
81 #include <qstringlist.h>
83 #include "GEOMImpl_Types.hxx"
87 //=======================================================================
88 // function : GEOMBase()
89 // purpose : Constructor
90 //=======================================================================
96 //=======================================================================
97 // function : ~GEOMBase()
98 // purpose : Destructor
99 //=======================================================================
100 GEOMBase::~GEOMBase()
104 //=====================================================================================
105 // function : GetShapeFromIOR()
106 // purpose : exist also as static method !
107 //=====================================================================================
108 TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
111 if(IOR.stripWhiteSpace().isEmpty())
114 CORBA::Object_var obj = GeometryGUI::GetORB()->string_to_object((char*)(IOR.latin1()));
115 if(CORBA::is_nil(obj))
117 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
118 if (GeomObject->_is_nil())
121 result = GeometryGUI::GetGeomGUI()->GetShapeReader().GetShape(GeometryGUI::GetGeomGUI()->GetGeomGen(), GeomObject);
126 //=====================================================================================
127 // function : GetIndex()
128 // purpose : Get the index of a sub shape in a main shape : index start at 1
129 //=====================================================================================
130 int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
132 if(shape.IsNull() || subshape.IsNull())
135 TopTools_IndexedMapOfShape anIndices;
136 TopExp::MapShapes(shape, anIndices);
137 if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
143 //=======================================================================
144 // function : GetTopoFromSelection()
145 // purpose : Define tds from a single selection and retuen true
146 //=======================================================================
147 bool GEOMBase::GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds)
149 if(Sel->IObjectCount() != 1)
152 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
155 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
156 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
157 SALOMEDS::GenericAttribute_var anAttr;
158 SALOMEDS::AttributeIOR_var anIOR;
159 if(!obj->_is_nil()) {
160 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
161 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
162 tds = GetShapeFromIOR(anIOR->Value());
174 //=======================================================================
175 // function : GetNameOfSelectedIObjects()
176 // purpose : Define the name geom++ or other name of mono or multi sel.
177 //=======================================================================
178 int GEOMBase::GetNameOfSelectedIObjects( SALOME_Selection* theSel,
180 const bool theShapesOnly )
182 if ( !theShapesOnly )
184 int nbSel = theSel->IObjectCount();
187 Handle(SALOME_InteractiveObject) anIObj = theSel->firstIObject();
188 theName = anIObj->getName();
191 theName = QObject::tr("%1_objects").arg(nbSel);
198 GEOM::ListOfGO anObjs;
199 ConvertListOfIOInListOfGO( theSel->StoredIObjects(), anObjs, theShapesOnly );
200 if ( anObjs.length() == 1 )
201 theName = GetName( anObjs[ 0 ] );
203 theName = QString( "%1_objects" ).arg( anObjs.length() );
205 return anObjs.length();
210 //=================================================================================
211 // function : GetShapeTypeString()
212 // purpose : for a single shape
213 //=================================================================================
214 bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
216 if(aShape.IsNull()) {
217 aTypeString = "aNullShape";
220 switch(aShape.ShapeType())
222 case TopAbs_COMPOUND:
224 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND"));
227 case TopAbs_COMPSOLID:
229 aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID")) ;
234 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID")) ;
239 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL")) ;
244 BRepAdaptor_Surface surf(TopoDS::Face(aShape));
245 if(surf.GetType() == GeomAbs_Plane) {
246 aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE"));
249 else if(surf.GetType() == GeomAbs_Cylinder) {
250 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER"));
253 else if(surf.GetType() == GeomAbs_Sphere) {
254 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE"));
257 else if(surf.GetType() == GeomAbs_Torus) {
258 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS"));
261 else if(surf.GetType() == GeomAbs_Cone) {
262 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE"));
266 aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE"));
272 aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE"));
277 BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
278 if(curv.GetType() == GeomAbs_Line) {
279 if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
280 aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE"));
282 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
285 else if(curv.GetType() == GeomAbs_Circle) {
287 aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE"));
289 aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC"));
293 aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE"));
299 aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX"));
304 aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE"));
312 //=======================================================================
313 // function : ConvertIORinGEOMAISShape()
315 //=======================================================================
316 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
318 Handle(GEOM_AISShape) resultShape;
321 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
322 SALOMEDS::SObject_var anObj = aStudy->FindObjectIOR( IOR );
323 if ( anObj->_is_nil() )
326 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
327 for(int i = 0; i < nbSf; i++) {
328 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
329 if(sf->getTypeView() == VIEW_OCC) {
330 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
331 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
333 AIS_ListOfInteractive List;
334 ic->DisplayedObjects(List);
335 AIS_ListOfInteractive List1;
336 ic->ObjectsInCollector(List1);
339 AIS_ListIteratorOfListOfInteractive ite(List);
341 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
342 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
344 Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
345 if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID()) == 0) {
346 if(!onlyInActiveView ||
347 sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
363 //=======================================================================
364 // function : ConvertIORinGEOMActor()
366 //=======================================================================
367 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
371 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
372 SALOMEDS::SObject_var anObj = aStudy->FindObjectIOR( IOR );
373 if ( anObj->_is_nil() )
374 return GEOM_Actor::New();
376 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
377 for(int i = 0; i < nbSf; i++) {
378 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
379 if(sf->getTypeView() == VIEW_VTK) {
380 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->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()) == 0) {
390 if(!onlyInActiveView ||
391 sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()) {
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 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
418 for ( int i = 0; i < nbSf; i++ )
420 QAD_StudyFrame* aStudyFrame =
421 QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame( i );
423 if ( aStudyFrame->getTypeView() != VIEW_OCC )
426 OCCViewer_Viewer3d* v3d =
427 ((OCCViewer_ViewFrame*)aStudyFrame->getRightFrame()->getViewFrame())->getViewer();
429 Handle(AIS_InteractiveContext) anIC = v3d->getAISContext();
431 AIS_ListOfInteractive aList;
432 anIC->DisplayedObjects( aList );
433 anIC->ObjectsInCollector( aList );
435 AIS_ListIteratorOfListOfInteractive anIter( aList );
436 for ( ; anIter.More(); anIter.Next() )
438 Handle(SALOME_InteractiveObject) anObj =
439 Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
441 if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
443 if( isOnlyInActiveView )
445 if ( aStudyFrame == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame() )
446 return anIter.Value();
449 return anIter.Value();
454 return Handle(AIS_InteractiveObject)();
458 //=======================================================================
459 // function : ConvertIOinGEOMAISShape()
461 //=======================================================================
462 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
464 Handle(GEOM_AISShape) res;
466 if ( !IO->hasEntry() )
472 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
473 for(int i = 0; i < nbSf; i++) {
474 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
475 if(sf->getTypeView() == VIEW_OCC) {
476 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
477 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
479 AIS_ListOfInteractive List;
480 ic->DisplayedObjects(List);
481 AIS_ListOfInteractive List1;
482 ic->ObjectsInCollector(List1);
485 AIS_ListIteratorOfListOfInteractive ite(List);
488 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
490 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
493 if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
497 if(sf == QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame())
520 //=======================================================================
521 // function : ConvertIOinGEOMShape()
523 //=======================================================================
524 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult)
526 GEOM::GEOM_Object_var aShape;
531 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
532 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IO->getEntry());
533 SALOMEDS::GenericAttribute_var anAttr;
534 SALOMEDS::AttributeIOR_var anIOR;
535 if(!obj->_is_nil()) {
536 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
537 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
538 aShape = GeometryGUI::GetGeomGUI()->GetGeomGen()->GetIORFromString(anIOR->Value());
539 if(!CORBA::is_nil(aShape))
541 return aShape._retn();
545 return GEOM::GEOM_Object::_nil();
549 //=======================================================================
550 // function : ConvertListOfIOInListOfIOR()
552 //=======================================================================
553 void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
555 int nbSel = aList.Extent();
556 listIOR.length(nbSel);
558 SALOME_ListIteratorOfListIO It(aList);
559 for(int i=0; It.More(); It.Next(), i++) {
560 Handle(SALOME_InteractiveObject) IObject = It.Value();
561 if(IObject->hasEntry()) {
562 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
563 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
564 SALOMEDS::GenericAttribute_var anAttr;
565 SALOMEDS::AttributeIOR_var anIOR;
566 if(!obj->_is_nil() && obj->FindAttribute(anAttr, "AttributeIOR")) {
567 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
568 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
569 CORBA::ORB_var& _orb = init.orb();
570 CORBA::String_var theValue = anIOR->Value();
571 CORBA::Object_var theObj = _orb->string_to_object(theValue);
572 if(theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
573 listIOR[j] = CORBA::string_dup(theValue);
583 //=======================================================================
584 // function : ConvertIOinGEOMObject()
586 //=======================================================================
587 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO,
588 Standard_Boolean& theResult )
590 theResult = Standard_False;
591 GEOM::GEOM_Object_var aReturnObject;
592 if ( !theIO.IsNull() )
594 const char* anEntry = theIO->getEntry();
595 SALOMEDS::SObject_var aSObj = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->FindObjectID( anEntry );
596 if ( !CORBA::is_nil( aSObj ) )
598 aReturnObject = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
599 theResult = !CORBA::is_nil( aReturnObject );
602 return aReturnObject._retn();
606 //=======================================================================
607 // function : ConvertListOfIOInListOfGO()
609 //=======================================================================
610 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
611 GEOM::ListOfGO& theListGO,
612 const bool theShapesOnly )
614 int nbSel = theList.Extent();
615 theListGO.length( nbSel );
616 SALOME_ListIteratorOfListIO anIter( theList );
617 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
619 for ( int i=0; anIter.More(); anIter.Next(), i++ )
621 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
622 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( anIObj->getEntry() );
624 if ( !aSObj->_is_nil() )
626 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aSObj->GetObject());
627 if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
628 theListGO[ j++ ] = aGeomObj;
632 theListGO.length( j );
635 //=================================================================================
636 // function : CreateArrowForLinearEdge()
637 // purpose : Create a cone topology to be used to display an arrow in the middle
638 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
639 //=================================================================================
640 bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
642 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC || tds.ShapeType() != TopAbs_EDGE)
645 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
646 Handle( V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
647 Standard_Real Width, Height;
648 view3d->Size(Width, Height);
649 const Standard_Real aHeight = (Width + Height) / 50.0;
652 Standard_Real first, last;
653 Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
657 const Standard_Real param = (first+last) / 2.0;
658 gp_Pnt middleParamPoint;
660 curv->D1( param, middleParamPoint, V1);
661 if(V1.Magnitude() < Precision::Confusion())
664 /* Topology orientation not geom orientation */
665 if(tds.Orientation() == TopAbs_REVERSED)
668 gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
669 const Standard_Real radius1 = aHeight / 5.0;
670 if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
671 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
675 catch(Standard_Failure) {
676 // OCC failures are hard to catch in GUI.
677 // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
678 // in SALOME environment : compilation error !
684 //=================================================================================
685 // function : VertexToPoint()
686 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
687 //=================================================================================
688 bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
690 if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
692 P = BRep_Tool::Pnt(TopoDS::Vertex(S));
697 //=================================================================================
698 // function : GetBipointDxDyDz()
700 //=================================================================================
701 void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
703 dx = P2.X() - P1.X();
704 dy = P2.Y() - P1.Y();
705 dz = P2.Z() - P1.Z();
710 //=================================================================================
711 // function : LinearEdgeExtremities()
712 // purpose : If S can be converted in a linear edge and if initial an final points
713 // : distance is sufficient, returns true else returns false.
714 // : Resulting points are respectively P1 and P2
715 //=================================================================================
716 bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
718 if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
720 BRepAdaptor_Curve curv(TopoDS::Edge(S));
721 if(curv.GetType() != GeomAbs_Line)
724 curv.D0(curv.FirstParameter(), P1);
725 curv.D0(curv.LastParameter(), P2);
727 if(P1.Distance(P2) <= Precision::Confusion())
734 //=======================================================================
735 // function : Parameter()
736 // purpose : return a parameter (float) from a dialog box
738 // avalue1 : is a float or integer used as a default value displayed
739 // aTitle1 : is the title for aValue1
740 // aTitle : is the main title
741 // bottom : maximum value to be entered
742 // top : minimum value to be entered
743 // decimals : number of decimals
744 //=======================================================================
745 double GEOMBase::Parameter(Standard_Boolean& res, const char* aValue1, const char* aTitle1, const char* aTitle, const double bottom, const double top, const int decimals)
747 GEOMBase_aParameterDlg * Dialog = new GEOMBase_aParameterDlg(aValue1, aTitle1, QAD_Application::getDesktop(), aTitle, TRUE, 0, bottom, top, decimals);
748 int r = Dialog->exec();
750 if(r == QDialog::Accepted) {
752 X = Dialog->getValue();
755 res = Standard_False;
761 //=======================================================================
762 // function : SelectionByNameInDialogs()
763 // purpose : Called when user has entered a name of object in a LineEdit.
764 // : The selection is changed. Dialog box will receive the
765 // : corresponding signal to manage this event.
766 //=======================================================================
767 bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, SALOME_Selection* Sel)
769 /* Find SObject with name in component GEOM */
770 SALOMEDS::Study_var ST = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
771 SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject;
772 listSO = ST->FindObjectByName(objectUserName, "GEOM");
774 if(listSO->length() < 1) {
775 const QString caption = QObject::tr("GEOM_WRN_WARNING");
776 const QString text = QObject::tr("GEOM_NAME_INCORRECT");
777 const QString button0 = QObject::tr("GEOM_BUT_OK");
778 QAD_MessageBox::error1(aWidget, caption, text, button0);
781 /* More than one object with same name */
782 if(listSO->length() > 1) {
783 const QString caption = QObject::tr("GEOM_WRN_WARNING");
784 const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
785 const QString button0 = QObject::tr("GEOM_BUT_OK") ;
786 QAD_MessageBox::error1(aWidget, caption, text, button0) ;
790 SALOMEDS::SObject_var theObj = listSO[0];
791 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
792 Standard_CString anEntry = theObj->GetID();
793 char* aCopyobjectUserName = CORBA::string_dup(objectUserName);
794 Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(anEntry, "GEOM", aCopyobjectUserName);
795 delete(aCopyobjectUserName);
797 /* Add as a selected object */
798 /* Clear any previous selection : */
799 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
800 Sel->ClearIObjects();
806 //=======================================================================
807 // function : DefineDlgPosition()
808 // purpose : Define x and y the default position for a dialog box
809 //=======================================================================
810 bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
812 /* Here the position is on the bottom right corner - 10 */
813 QAD_Desktop* PP = QAD_Application::getDesktop();
814 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
815 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
820 //=======================================================================
821 // function : GetDefaultName()
822 // purpose : Generates default names
823 //=======================================================================
824 QString GEOMBase::GetDefaultName(const QString& theOperation)
826 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
829 SALOMEDS::SObject_var obj;
833 aName = theOperation+"_"+QString::number(++aNumber);
834 obj = aStudy->FindObject(aName);
836 while (!obj->_is_nil());
842 //=======================================================================
843 // function : ShowErrorMessage()
844 // purpose : Shows message box with error code and comment
845 //=======================================================================
846 void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
848 QString anErrorCode(theErrorCode);
849 QString aComment(theComment);
852 if (!anErrorCode.isEmpty())
853 aText.append("\n" + QObject::tr(anErrorCode));
854 if (!aComment.isEmpty())
855 aText.append("\n" + QString(theComment));
857 QAD_MessageBox::error1( QAD_Application::getDesktop(), QObject::tr( "GEOM_ERROR" ),
858 QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
862 //=======================================================================
863 // function : GetObjectFromIOR()
864 // purpose : returns a GEOM_Object by given IOR (string)
865 //=======================================================================
866 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
868 GEOM::GEOM_Object_var anObject;
869 if ( theIOR == NULL || strlen( theIOR ) == 0 )
870 return anObject._retn(); // returning nil object
872 anObject = GEOM::GEOM_Object::_narrow( GeometryGUI::GetORB()->string_to_object( theIOR ) );
873 return anObject._retn();
876 //=======================================================================
877 // function : GetIORFromObject()
878 // purpose : returns IOR of a given GEOM_Object
879 //=======================================================================
880 char* GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
882 if ( CORBA::is_nil( theObject ) )
885 return GeometryGUI::GetORB()->object_to_string( theObject );
888 //=======================================================================
889 // function : GetShape()
890 // purpose : returns a TopoDS_Shape stored in GEOM_Object
891 //=======================================================================
892 bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
894 if ( !CORBA::is_nil( theObject ) )
896 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( GeometryGUI::GetGeomGUI()->GetGeomGen(), theObject );
897 if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
899 theShape = aTopoDSShape;
906 //=======================================================================
907 // function : GetName()
908 // purpose : Get name of object
909 //=======================================================================
910 const char* GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
912 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
916 string anIOR = GeometryGUI::GetORB()->object_to_string( theObj );
919 SALOMEDS::SObject_var aSObj = aStudy->getStudyDocument()->FindObjectIOR( anIOR.c_str() );
920 SALOMEDS::GenericAttribute_var anAttr;
922 if ( !aSObj->_is_nil() && aSObj->FindAttribute( anAttr, "AttributeName") )
924 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
925 return aNameAttr->Value();
933 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
935 return !theObj->_is_nil() && theObj->IsShape();