1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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 \class GEOM_AISShape GEOM_AISShape.hxx
28 #include "GEOM_AISShape.hxx"
29 #include "GEOM_AISVector.hxx"
31 #include <GEOMUtils.hxx>
33 #include <Basics_OCCTVersion.hxx>
35 // Open CASCADE Includes
36 #include <AIS_InteractiveContext.hxx>
37 #include <BRepAdaptor_Surface.hxx>
38 #include <BRep_Tool.hxx>
39 #include <GCPnts_AbscissaPoint.hxx>
40 #include <GeomAdaptor_Curve.hxx>
41 #include <Graphic3d_ArrayOfPoints.hxx>
42 #include <Graphic3d_AspectFillArea3d.hxx>
43 #include <Graphic3d_AspectLine3d.hxx>
44 #include <Graphic3d_AspectMarker3d.hxx>
45 #include <Graphic3d_AspectText3d.hxx>
46 #include <Prs3d_Arrow.hxx>
47 #include <Prs3d_IsoAspect.hxx>
48 #include <Prs3d_ShadingAspect.hxx>
49 #include <SelectBasics_SensitiveEntity.hxx>
50 #include <SelectMgr_EntityOwner.hxx>
51 #include <SelectMgr_IndexedMapOfOwner.hxx>
52 #include <SelectMgr_Selection.hxx>
53 #include <StdPrs_ShadedShape.hxx>
54 #include <StdSelect_BRepOwner.hxx>
55 #include <StdSelect_DisplayMode.hxx>
56 #include <TColStd_IndexedMapOfInteger.hxx>
57 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <TColStd_ListOfInteger.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TopoDS_Edge.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopoDS_Vertex.hxx>
66 #include <V3d_View.hxx>
71 #if OCC_VERSION_LARGE > 0x06070200
72 #include <Prs3d_VertexDrawMode.hxx>
75 #if OCC_VERSION_MAJOR < 7
76 #include <StdPrs_WFDeflectionShape.hxx>
78 #include <StdPrs_WFShape.hxx>
81 #include <SalomeApp_Tools.h>
82 #include <SUIT_Session.h>
83 #include <SUIT_ResourceMgr.h>
85 OCCT_IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
87 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
88 Quantity_Color GEOM_AISShape::myTopLevelColor;
91 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
92 const Handle(AIS_InteractiveContext)& theIC,
93 SelectMgr_IndexedMapOfOwner& theMap )
95 if ( theObj.IsNull() || theIC.IsNull() )
98 TColStd_ListOfInteger modes;
99 theIC->ActivatedModes( theObj, modes );
101 TColStd_ListIteratorOfListOfInteger itr( modes );
102 for (; itr.More(); itr.Next() ) {
104 if ( !theObj->HasSelection( m ) )
107 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
109 for ( sel->Init(); sel->More(); sel->Next() ) {
110 #if OCC_VERSION_LARGE > 0x06080100
111 const Handle(SelectMgr_SensitiveEntity) aHSenEntity = sel->Sensitive();
112 if( aHSenEntity.IsNull() )
115 Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
117 Handle(SelectBasics_SensitiveEntity) entity = sel->Sensitive();
119 if ( entity.IsNull() )
121 Handle(SelectMgr_EntityOwner) owner =
122 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
123 if ( !owner.IsNull() )
129 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
130 const TopoDS_Shape& aMainShape,
131 const SelectMgr_IndexedMapOfOwner& anAllMap,
132 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
134 TopTools_IndexedMapOfShape aMapOfShapes;
135 TopExp::MapShapes(aMainShape, aMapOfShapes);
137 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
138 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
139 if ( anOwner.IsNull() || !anOwner->HasShape() )
142 const TopoDS_Shape& aSubShape = anOwner->Shape();
143 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
144 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
147 if ( !aToHiliteMap.Contains( anOwner ) )
148 aToHiliteMap.Add( anOwner );
152 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
153 const Standard_CString aName)
154 : SALOME_AISShape(shape),
156 myDisplayVectors(false),
157 myDisplayVertices(false),
158 myFieldDataType(GEOM::FDT_Double),
160 myFieldStepRangeMin(0),
161 myFieldStepRangeMax(0)
163 //rnv: Commented to avoid bug with local selection
164 //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
166 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
167 myPrevDisplayMode = 0;
169 myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
171 myTopLevel = Standard_False;
172 Graphic3d_MaterialAspect aMatAspect;
173 if ( !HasMaterial() ) {
174 aMatAspect.SetAmbient( 0.5 );
175 aMatAspect.SetDiffuse( 0.5 );
176 aMatAspect.SetEmissive( 0.5 );
177 aMatAspect.SetShininess(0.5 );
178 aMatAspect.SetSpecular( 0.5 );
180 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
181 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
185 GEOM_AISShape::~GEOM_AISShape()
189 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io)
194 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO()
196 Handle(SALOME_InteractiveObject) IO;
197 if ( !GetOwner().IsNull() )
198 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
202 Standard_Boolean GEOM_AISShape::hasIO()
204 return !getIO().IsNull();
207 void GEOM_AISShape::setName(const Standard_CString aName)
211 Handle(SALOME_InteractiveObject) IO = getIO();
216 Standard_CString GEOM_AISShape::getName()
218 return myName.ToCString();
221 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
222 const Handle(Prs3d_Presentation)& aPrs,
223 const Standard_Integer aMode)
225 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
227 Handle(AIS_InteractiveContext) anIC = GetContext();
228 // AKL: use old behavior to avoid keeping object's wireframe
229 // if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos')
230 // calling popup menu over(!) the shape in OCC viewer.
231 anIC->SetToHilightSelected( false );
233 bool anIsField = !myFieldStepData.isEmpty();
234 bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
235 bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
237 #if OCC_VERSION_LARGE > 0x06070200
238 if (isShowVertices())
239 myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
242 // StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
243 bool isTopLev = isTopLevel() && switchTopLevel();
246 case CustomHighlight:
249 SetColor(topLevelColor());
250 Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
251 anAspect->SetColor( topLevelColor() );
252 Attributes()->SetWireAspect( anAspect );
254 if( !isTopLev && anIsColorField && myFieldDimension == 1 )
255 drawField( aPrs, false, aMode == CustomHighlight );
257 #if OCC_VERSION_MAJOR < 7
258 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
260 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
266 shadingMode(aPresentationManager, aPrs, aMode);
269 case ShadingWithEdges:
271 myDrawer->SetFaceBoundaryDraw( Standard_True );
272 shadingMode(aPresentationManager, aPrs, Shading);
273 if( anIsColorField && myFieldDimension == 1 ) {
274 myDrawer->SetFaceBoundaryDraw( Standard_False );
281 #ifdef USE_TEXTURED_SHAPE
282 AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode);
284 AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
290 const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
291 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
292 for ( ; Exp.More(); Exp.Next() ) {
293 TopoDS_Vertex aV1, aV2;
294 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
296 // draw curve direction (issue 0021087)
297 anEdgeE.Orientation( TopAbs_FORWARD );
299 if ( anEdgeE.IsNull() ) continue;
301 TopExp::Vertices(anEdgeE, aV1, aV2);
302 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
303 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
307 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
309 if ( C.IsNull() ) continue;
311 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
312 C->D1(lp, aP2, aDirVec);
314 C->D1(fp, aP1, aDirVec);
318 GeomAdaptor_Curve aAdC;
319 aAdC.Load(C, fp, lp);
320 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
322 if (aDist > gp::Resolution()) {
324 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
329 Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
334 // draw color field on vertices
335 if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
340 drawField( aPrs, true );
345 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
348 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
350 myShadingColor = aCol;
353 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
355 myEdgesInShadingColor = aCol;
358 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
363 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
364 const Standard_Boolean aHighlight )
366 Handle(AIS_InteractiveObject) anObj = this;
367 Handle(AIS_InteractiveContext) anIC = GetContext();
368 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
371 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
372 anIC->SetAutomaticHilight( false );
374 anIC->ClearSelected( false );
377 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
379 // Get entity owners for all activated selection modes
380 getEntityOwners( anObj, anIC, anAllMap );
382 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
383 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
386 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
387 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
390 anIC->SetAutomaticHilight( isAutoHilight );
391 anIC->HilightSelected( false );
394 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
396 myDisplayVectors = isDisplayed;
399 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
401 myDisplayVertices = isDisplayed;
404 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
406 myDisplayName = isDisplayed;
409 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
410 const Handle(Prs3d_Presentation)& aPrs,
411 const Standard_Integer aMode)
413 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
415 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
416 aMatAspect.SetTransparency(Transparency());
417 Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
418 Graphic3d_MaterialAspect currentBackMaterial = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
419 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
420 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial );
422 if( isTopLevel() && switchTopLevel() )
423 myDrawer->ShadingAspect()->SetColor( topLevelColor() );
425 if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
426 myDrawer->ShadingAspect()->SetColor(myShadingColor);
428 myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
431 bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
432 if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
438 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
439 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
440 #ifdef USE_TEXTURED_SHAPE
441 AIS_TexturedShape::Compute(aPresentationManager, aPrs, aMode);
443 AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
448 Standard_Boolean GEOM_AISShape::isTopLevel()
453 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
457 myPrevDisplayMode = DisplayMode();
459 switch(topLevelDisplayMode()) {
460 case TopWireFrame : dm = Wireframe; break;
461 case TopShading : dm = Shading; break;
462 case TopShadingWithEdges : dm = ShadingWithEdges; break;
463 default : dm = myPrevDisplayMode; break;
468 SetDisplayMode(myPrevDisplayMode);
473 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
475 myPrevDisplayMode = mode;
478 Quantity_Color GEOM_AISShape::topLevelColor()
480 return myTopLevelColor;
483 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
488 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
493 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
498 Standard_Boolean GEOM_AISShape::switchTopLevel()
500 return myTopLevelDm != TopShowAdditionalWActor;
503 Standard_Boolean GEOM_AISShape::toActivate()
505 return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
508 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
509 const int theFieldDimension,
510 const QList<QVariant>& theFieldStepData,
511 const TCollection_AsciiString& theFieldStepName,
512 const double theFieldStepRangeMin,
513 const double theFieldStepRangeMax )
515 myFieldDataType = theFieldDataType;
516 myFieldDimension = theFieldDimension;
517 myFieldStepData = theFieldStepData;
518 myFieldStepName = theFieldStepName;
519 myFieldStepRangeMin = theFieldStepRangeMin;
520 myFieldStepRangeMax = theFieldStepRangeMax;
523 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
524 int& theFieldDimension,
525 QList<QVariant>& theFieldStepData,
526 TCollection_AsciiString& theFieldStepName,
527 double& theFieldStepRangeMin,
528 double& theFieldStepRangeMax ) const
530 theFieldDataType = myFieldDataType;
531 theFieldDimension = myFieldDimension;
532 theFieldStepData = myFieldStepData;
533 theFieldStepName = myFieldStepName;
534 theFieldStepRangeMin = myFieldStepRangeMin;
535 theFieldStepRangeMax = myFieldStepRangeMax;
538 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
539 const bool theIsString,
540 const bool theIsHighlight )
542 if( myFieldStepData.isEmpty() )
545 QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
547 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
548 switch( myFieldDimension )
550 case 0: aShapeType = TopAbs_VERTEX; break;
551 case 1: aShapeType = TopAbs_EDGE; break;
552 case 2: aShapeType = TopAbs_FACE; break;
553 case 3: aShapeType = TopAbs_SOLID; break;
554 case -1: aShapeType = TopAbs_VERTEX; break;
557 TopTools_IndexedMapOfShape aShapeMap;
558 TopExp::MapShapes( myshape, aShapeMap );
560 TColStd_IndexedMapOfInteger anIndexMap;
562 TopExp_Explorer anExp;
563 for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
565 TopoDS_Shape aSubShape = anExp.Current();
566 if( !aSubShape.IsNull() )
568 Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
569 if( anIndexMap.Contains( aSubShapeIndex ) )
572 anIndexMap.Add( aSubShapeIndex );
574 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
578 if( aFieldStepDataIter.hasNext() )
580 const QVariant& aVariant = aFieldStepDataIter.next();
582 aString = aVariant.toString();
584 aQColor = aVariant.value<QColor>();
592 if( computeMassCenter( aSubShape, aCenter ) )
594 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
596 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
597 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
598 anAspectText3d->SetColor( myLabelColor );
599 aGroup->SetPrimitivesAspect( anAspectText3d );
601 aGroup->Text( aString.toLatin1().constData(), aVertex, 14 );
606 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
607 if( myFieldDimension == 0 )
609 TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
610 if( !aVertexShape.IsNull() )
612 gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
614 Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
615 anAspectMarker3d->SetColor( aColor );
616 anAspectMarker3d->SetType( Aspect_TOM_POINT );
617 anAspectMarker3d->SetScale( 10.0 );
618 aGroup->SetPrimitivesAspect( anAspectMarker3d );
620 Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
621 anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
623 aGroup->AddPrimitiveArray( anArray );
626 else if( myFieldDimension == 1 )
628 myDrawer->WireAspect()->SetColor( aColor );
630 myDrawer->WireAspect()->SetWidth( myOwnWidth );
632 myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
633 #if OCC_VERSION_MAJOR < 7
634 StdPrs_WFDeflectionShape::Add( thePrs, aSubShape, myDrawer );
636 StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
639 else if( myFieldDimension == 2 ||
640 myFieldDimension == 3 ||
641 myFieldDimension == -1 )
643 myDrawer->ShadingAspect()->SetColor( aColor );
644 StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
651 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
653 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
655 gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
656 gp_Pnt aCenter = anAx3.Location();
658 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
660 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
661 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
662 anAspectText3d->SetColor( myLabelColor );
663 aGroup->SetPrimitivesAspect( anAspectText3d );
665 const char* aName = getIO()->getName();
666 aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
669 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
672 theCenter.SetCoord( 0,0,0 );
673 Standard_Integer aNbPoints = 0;
675 if ( theShape.ShapeType() == TopAbs_EDGE )
678 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
679 if ( !curve.IsNull() )
681 theCenter = curve->Value( 0.5 * ( f + l ));
685 else if ( theShape.ShapeType() == TopAbs_FACE )
687 const TopoDS_Face& F = TopoDS::Face( theShape );
688 BRepAdaptor_Surface surface( F );
691 Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
692 if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
696 const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
697 const Poly_Array1OfTriangle& trias = triangulation->Triangles();
698 Standard_Integer n1,n2,n3;
699 for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
701 trias( iT ).Get( n1,n2,n3 );
702 const gp_Pnt2d& uv1 = uvArray( n1 );
703 const gp_Pnt2d& uv2 = uvArray( n2 );
704 const gp_Pnt2d& uv3 = uvArray( n3 );
705 double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
706 ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
707 C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
710 if ( A > std::numeric_limits<double>::min() )
713 theCenter = surface.Value( C.X(), C.Y() );
717 if ( aNbPoints == 0 )
719 theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
720 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
725 if ( aNbPoints == 0 )
727 TopExp_Explorer anExp;
728 for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
730 TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
731 if( !aVertex.IsNull() )
733 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
734 theCenter.ChangeCoord() += aPnt.XYZ();
741 theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;