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 // Open CASCADE Includes
34 #include <AIS_InteractiveContext.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 #include <BRep_Tool.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
38 #include <GeomAdaptor_Curve.hxx>
39 #include <Graphic3d_ArrayOfPoints.hxx>
40 #include <Graphic3d_AspectFillArea3d.hxx>
41 #include <Graphic3d_AspectLine3d.hxx>
42 #include <Graphic3d_AspectMarker3d.hxx>
43 #include <Graphic3d_AspectText3d.hxx>
45 #include <Prs3d_Arrow.hxx>
46 #include <Prs3d_IsoAspect.hxx>
47 #include <Prs3d_ShadingAspect.hxx>
48 #include <SelectBasics_SensitiveEntity.hxx>
49 #include <SelectMgr_EntityOwner.hxx>
50 #include <SelectMgr_IndexedMapOfOwner.hxx>
51 #include <SelectMgr_Selection.hxx>
52 #include <StdPrs_ShadedShape.hxx>
53 #include <StdPrs_ToolTriangulatedShape.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>
70 #include <Prs3d_VertexDrawMode.hxx>
71 #include <StdPrs_WFShape.hxx>
73 #include <SalomeApp_Tools.h>
74 #include <SUIT_Session.h>
75 #include <SUIT_ResourceMgr.h>
77 IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
79 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
80 Quantity_Color GEOM_AISShape::myTopLevelColor;
83 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
84 const Handle(AIS_InteractiveContext)& theIC,
85 SelectMgr_IndexedMapOfOwner& theMap )
87 if ( theObj.IsNull() || theIC.IsNull() )
90 TColStd_ListOfInteger modes;
91 theIC->ActivatedModes( theObj, modes );
93 TColStd_ListIteratorOfListOfInteger itr( modes );
94 for (; itr.More(); itr.Next() ) {
96 if ( !theObj->HasSelection( m ) )
99 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
101 for ( sel->Init(); sel->More(); sel->Next() ) {
102 const Handle(SelectMgr_SensitiveEntity) aHSenEntity = sel->Sensitive();
103 if( aHSenEntity.IsNull() )
106 Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
107 if ( entity.IsNull() )
109 Handle(SelectMgr_EntityOwner) owner =
110 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
111 if ( !owner.IsNull() )
117 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
118 const TopoDS_Shape& aMainShape,
119 const SelectMgr_IndexedMapOfOwner& anAllMap,
120 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
122 TopTools_IndexedMapOfShape aMapOfShapes;
123 TopExp::MapShapes(aMainShape, aMapOfShapes);
125 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
126 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
127 if ( anOwner.IsNull() || !anOwner->HasShape() )
130 const TopoDS_Shape& aSubShape = anOwner->Shape();
131 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
132 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
135 if ( !aToHiliteMap.Contains( anOwner ) )
136 aToHiliteMap.Add( anOwner );
140 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
141 const Standard_CString aName)
142 : SALOME_AISShape(shape),
144 myDisplayVectors(false),
145 myDisplayVertices(false),
146 myFieldDataType(GEOM::FDT_Double),
148 myFieldStepRangeMin(0),
149 myFieldStepRangeMax(0)
151 //rnv: Commented to avoid bug with local selection
152 //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
154 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
155 myPrevDisplayMode = 0;
157 myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
159 myTopLevel = Standard_False;
160 Graphic3d_MaterialAspect aMatAspect;
161 if ( !HasMaterial() ) {
162 aMatAspect.SetAmbient( 0.5 );
163 aMatAspect.SetDiffuse( 0.5 );
164 aMatAspect.SetEmissive( 0.5 );
165 aMatAspect.SetShininess(0.5 );
166 aMatAspect.SetSpecular( 0.5 );
168 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
169 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
173 GEOM_AISShape::~GEOM_AISShape()
177 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io)
182 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO()
184 Handle(SALOME_InteractiveObject) IO;
185 if ( !GetOwner().IsNull() )
186 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
190 Standard_Boolean GEOM_AISShape::hasIO()
192 return !getIO().IsNull();
195 void GEOM_AISShape::setName(const Standard_CString aName)
199 Handle(SALOME_InteractiveObject) IO = getIO();
204 Standard_CString GEOM_AISShape::getName()
206 return myName.ToCString();
209 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
210 const Handle(Prs3d_Presentation)& aPrs,
211 const Standard_Integer aMode)
213 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
215 Handle(AIS_InteractiveContext) anIC = GetContext();
216 // AKL: use old behavior to avoid keeping object's wireframe
217 // if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos')
218 // calling popup menu over(!) the shape in OCC viewer.
219 anIC->SetToHilightSelected( false );
221 bool anIsField = !myFieldStepData.isEmpty();
222 bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
223 bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
225 if (isShowVertices())
226 myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
228 // StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
229 bool isTopLev = isTopLevel() && switchTopLevel();
232 // Begin 0023271: [CEA 1823] Deflection Coefficient not taken into account in wireframe
234 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
236 // After this call if type of deflection is relative
237 // computed deflection coefficient is stored as absolute.
238 Prs3d::GetDeflection (myshape, myDrawer);
241 case CustomHighlight:
244 SetColor(topLevelColor());
245 Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
246 anAspect->SetColor( topLevelColor() );
247 Attributes()->SetWireAspect( anAspect );
249 if( !isTopLev && anIsColorField && myFieldDimension == 1 )
250 drawField( aPrs, false, aMode == CustomHighlight );
252 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
257 shadingMode(aPresentationManager, aPrs, aMode);
260 case ShadingWithEdges:
262 myDrawer->SetFaceBoundaryDraw( Standard_True );
263 shadingMode(aPresentationManager, aPrs, Shading);
264 if( anIsColorField && myFieldDimension == 1 ) {
265 myDrawer->SetFaceBoundaryDraw( Standard_False );
272 shadingMode(aPresentationManager, aPrs, Shading);
278 const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
279 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
280 for ( ; Exp.More(); Exp.Next() ) {
281 TopoDS_Vertex aV1, aV2;
282 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
284 // draw curve direction (issue 0021087)
285 anEdgeE.Orientation( TopAbs_FORWARD );
287 if ( anEdgeE.IsNull() ) continue;
289 TopExp::Vertices(anEdgeE, aV1, aV2);
290 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
291 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
295 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
297 if ( C.IsNull() ) continue;
299 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
300 C->D1(lp, aP2, aDirVec);
302 C->D1(fp, aP1, aDirVec);
306 GeomAdaptor_Curve aAdC;
307 aAdC.Load(C, fp, lp);
308 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
310 if (aDist > gp::Resolution()) {
312 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
317 Prs3d_Arrow::Draw(aPrs, aP2, aDir, M_PI/180.*5., aDist/10.);
322 // draw color field on vertices
323 if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
328 drawField( aPrs, true );
333 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
336 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
338 myShadingColor = aCol;
341 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
343 myEdgesInShadingColor = aCol;
346 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
351 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
352 const Standard_Boolean aHighlight )
354 Handle(AIS_InteractiveObject) anObj = this;
355 Handle(AIS_InteractiveContext) anIC = GetContext();
356 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
359 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
360 anIC->SetAutomaticHilight( false );
362 anIC->ClearSelected( false );
365 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
367 // Get entity owners for all activated selection modes
368 getEntityOwners( anObj, anIC, anAllMap );
370 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
371 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
374 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
375 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
378 anIC->SetAutomaticHilight( isAutoHilight );
379 anIC->HilightSelected( false );
382 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
384 myDisplayVectors = isDisplayed;
387 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
389 myDisplayVertices = isDisplayed;
392 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
394 myDisplayName = isDisplayed;
397 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
398 const Handle(Prs3d_Presentation)& aPrs,
399 const Standard_Integer aMode)
401 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
403 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
404 aMatAspect.SetTransparency(Transparency());
405 Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
406 Graphic3d_MaterialAspect currentBackMaterial = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
407 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
408 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial );
410 if( isTopLevel() && switchTopLevel() )
411 myDrawer->ShadingAspect()->SetColor( topLevelColor() );
413 if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
414 myDrawer->ShadingAspect()->SetColor(myShadingColor);
416 myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
419 bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
420 if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
426 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
427 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
428 SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
432 Standard_Boolean GEOM_AISShape::isTopLevel()
437 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
441 myPrevDisplayMode = DisplayMode();
443 switch(topLevelDisplayMode()) {
444 case TopWireFrame : dm = Wireframe; break;
445 case TopShading : dm = Shading; break;
446 case TopShadingWithEdges : dm = ShadingWithEdges; break;
447 default : dm = myPrevDisplayMode; break;
452 SetDisplayMode(myPrevDisplayMode);
457 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
459 myPrevDisplayMode = mode;
462 Quantity_Color GEOM_AISShape::topLevelColor()
464 return myTopLevelColor;
467 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
472 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
477 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
482 Standard_Boolean GEOM_AISShape::switchTopLevel()
484 return myTopLevelDm != TopShowAdditionalWActor;
487 Standard_Boolean GEOM_AISShape::toActivate()
489 return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
492 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
493 const int theFieldDimension,
494 const QList<QVariant>& theFieldStepData,
495 const TCollection_AsciiString& theFieldStepName,
496 const double theFieldStepRangeMin,
497 const double theFieldStepRangeMax )
499 myFieldDataType = theFieldDataType;
500 myFieldDimension = theFieldDimension;
501 myFieldStepData = theFieldStepData;
502 myFieldStepName = theFieldStepName;
503 myFieldStepRangeMin = theFieldStepRangeMin;
504 myFieldStepRangeMax = theFieldStepRangeMax;
507 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
508 int& theFieldDimension,
509 QList<QVariant>& theFieldStepData,
510 TCollection_AsciiString& theFieldStepName,
511 double& theFieldStepRangeMin,
512 double& theFieldStepRangeMax ) const
514 theFieldDataType = myFieldDataType;
515 theFieldDimension = myFieldDimension;
516 theFieldStepData = myFieldStepData;
517 theFieldStepName = myFieldStepName;
518 theFieldStepRangeMin = myFieldStepRangeMin;
519 theFieldStepRangeMax = myFieldStepRangeMax;
522 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
523 const bool theIsString,
524 const bool theIsHighlight )
526 if( myFieldStepData.isEmpty() )
529 QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
531 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
532 switch( myFieldDimension )
534 case 0: aShapeType = TopAbs_VERTEX; break;
535 case 1: aShapeType = TopAbs_EDGE; break;
536 case 2: aShapeType = TopAbs_FACE; break;
537 case 3: aShapeType = TopAbs_SOLID; break;
538 case -1: aShapeType = TopAbs_VERTEX; break;
541 TopTools_IndexedMapOfShape aShapeMap;
542 TopExp::MapShapes( myshape, aShapeMap );
544 TColStd_IndexedMapOfInteger anIndexMap;
546 TopExp_Explorer anExp;
547 for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
549 TopoDS_Shape aSubShape = anExp.Current();
550 if( !aSubShape.IsNull() )
552 Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
553 if( anIndexMap.Contains( aSubShapeIndex ) )
556 anIndexMap.Add( aSubShapeIndex );
558 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
562 if( aFieldStepDataIter.hasNext() )
564 const QVariant& aVariant = aFieldStepDataIter.next();
566 aString = aVariant.toString();
568 aQColor = aVariant.value<QColor>();
576 if( computeMassCenter( aSubShape, aCenter ) )
578 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
580 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
581 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
582 anAspectText3d->SetColor( myLabelColor );
583 aGroup->SetPrimitivesAspect( anAspectText3d );
585 aGroup->Text( aString.toUtf8().constData(), aVertex, 14 );
590 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
591 SetCustomColor( aSubShape, aColor );
592 if( myFieldDimension == 0 )
594 TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
595 if( !aVertexShape.IsNull() )
597 gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
599 Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
600 anAspectMarker3d->SetColor( aColor );
601 anAspectMarker3d->SetType( Aspect_TOM_POINT );
602 anAspectMarker3d->SetScale( 10.0 );
603 aGroup->SetPrimitivesAspect( anAspectMarker3d );
605 Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
606 anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
608 aGroup->AddPrimitiveArray( anArray );
611 else if( myFieldDimension == 1 )
613 myDrawer->WireAspect()->SetColor( aColor );
615 myDrawer->WireAspect()->SetWidth( myOwnWidth );
617 myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
619 StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
622 else if( myFieldDimension == 2 ||
623 myFieldDimension == 3 ||
624 myFieldDimension == -1 )
626 //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
627 //anAspect->SetColor( aColor );
628 //myDrawer->SetShadingAspect( anAspect );
629 //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
635 SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
636 thePrs, AIS_Shaded );
639 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
641 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
643 gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
644 gp_Pnt aCenter = anAx3.Location();
646 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
648 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
649 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
650 anAspectText3d->SetColor( myLabelColor );
651 aGroup->SetPrimitivesAspect( anAspectText3d );
653 const char* aName = getIO()->getName();
654 aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
657 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
660 theCenter.SetCoord( 0,0,0 );
661 Standard_Integer aNbPoints = 0;
663 if ( theShape.ShapeType() == TopAbs_EDGE )
666 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
667 if ( !curve.IsNull() )
669 theCenter = curve->Value( 0.5 * ( f + l ));
673 else if ( theShape.ShapeType() == TopAbs_FACE )
675 const TopoDS_Face& F = TopoDS::Face( theShape );
676 BRepAdaptor_Surface surface( F );
679 Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
680 if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
684 const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
685 const Poly_Array1OfTriangle& trias = triangulation->Triangles();
686 Standard_Integer n1,n2,n3;
687 for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
689 trias( iT ).Get( n1,n2,n3 );
690 const gp_Pnt2d& uv1 = uvArray( n1 );
691 const gp_Pnt2d& uv2 = uvArray( n2 );
692 const gp_Pnt2d& uv3 = uvArray( n3 );
693 double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
694 ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
695 C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
698 if ( A > std::numeric_limits<double>::min() )
701 theCenter = surface.Value( C.X(), C.Y() );
705 if ( aNbPoints == 0 )
707 theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
708 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
713 if ( aNbPoints == 0 )
715 TopExp_Explorer anExp;
716 for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
718 TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
719 if( !aVertex.IsNull() )
721 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
722 theCenter.ChangeCoord() += aPnt.XYZ();
729 theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;