1 // Copyright (C) 2007-2021 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>
42 #include <Graphic3d_ArrayOfPoints.hxx>
43 #include <Graphic3d_AspectFillArea3d.hxx>
44 #include <Graphic3d_AspectLine3d.hxx>
45 #include <Graphic3d_AspectMarker3d.hxx>
46 #include <Graphic3d_AspectText3d.hxx>
48 #include <Prs3d_Arrow.hxx>
49 #include <Prs3d_IsoAspect.hxx>
50 #include <Prs3d_ShadingAspect.hxx>
51 #include <Prs3d_VertexDrawMode.hxx>
52 #include <SelectBasics_SensitiveEntity.hxx>
53 #include <SelectMgr_EntityOwner.hxx>
54 #include <SelectMgr_IndexedMapOfOwner.hxx>
55 #include <SelectMgr_Selection.hxx>
56 #include <StdPrs_ShadedShape.hxx>
57 #include <StdPrs_ToolTriangulatedShape.hxx>
58 #include <StdPrs_WFShape.hxx>
59 #include <StdSelect_BRepOwner.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
61 #include <TColStd_ListIteratorOfListOfInteger.hxx>
62 #include <TColStd_ListOfInteger.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
67 #include <TopoDS_Edge.hxx>
68 #include <TopoDS_Shape.hxx>
69 #include <TopoDS_Vertex.hxx>
70 #include <V3d_View.hxx>
72 #include <Basics_OCCTVersion.hxx>
73 #if OCC_VERSION_LARGE >= 0x070400ff
74 #include <Graphic3d_Text.hxx>
76 #include <StdSelect_DisplayMode.hxx>
79 #include <SalomeApp_Tools.h>
80 #include <SUIT_Session.h>
81 #include <SUIT_ResourceMgr.h>
83 IMPLEMENT_STANDARD_RTTIEXT(GEOM_AISShape, SALOME_AISShape)
85 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::myTopLevelDm = GEOM_AISShape::TopKeepCurrent;
86 Quantity_Color GEOM_AISShape::myTopLevelColor;
89 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
90 const Handle(AIS_InteractiveContext)& theIC,
91 SelectMgr_IndexedMapOfOwner& theMap )
93 if ( theObj.IsNull() || theIC.IsNull() )
96 TColStd_ListOfInteger modes;
97 theIC->ActivatedModes( theObj, modes );
99 TColStd_ListIteratorOfListOfInteger itr( modes );
100 for (; itr.More(); itr.Next() ) {
102 if ( !theObj->HasSelection( m ) )
105 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
106 const NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>& selected = sel->Entities();
107 for ( NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator selIter( selected );
108 selIter.More(); selIter.Next() ) {
109 const Handle(SelectMgr_SensitiveEntity) aHSenEntity = selIter.Value();
110 if( aHSenEntity.IsNull() )
113 Handle(SelectBasics_SensitiveEntity) entity = aHSenEntity->BaseSensitive();
114 if ( entity.IsNull() )
116 const Handle(SelectMgr_EntityOwner)& owner = entity->OwnerId();
117 if ( !owner.IsNull() )
123 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
124 const TopoDS_Shape& aMainShape,
125 const SelectMgr_IndexedMapOfOwner& anAllMap,
126 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
128 TopTools_IndexedMapOfShape aMapOfShapes;
129 TopExp::MapShapes(aMainShape, aMapOfShapes);
131 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
132 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
133 if ( anOwner.IsNull() || !anOwner->HasShape() )
136 const TopoDS_Shape& aSubShape = anOwner->Shape();
137 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
138 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
141 if ( !aToHiliteMap.Contains( anOwner ) )
142 aToHiliteMap.Add( anOwner );
146 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
147 const Standard_CString aName)
148 : SALOME_AISShape(shape),
150 myDisplayVectors(false),
151 myDisplayVertices(false),
152 myFieldDataType(GEOM::FDT_Double),
154 myFieldStepRangeMin(0),
155 myFieldStepRangeMax(0)
157 //rnv: Commented to avoid bug with local selection
158 //SetHilightMode( CustomHighlight ); // override setting the mode to 0 inside AIS_Shape constructor
160 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
161 myPrevDisplayMode = 0;
163 myEdgesInShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
165 myTopLevel = Standard_False;
166 Graphic3d_MaterialAspect aMatAspect;
167 if ( !HasMaterial() ) {
168 #if OCC_VERSION_LARGE >= 0x07040000
169 aMatAspect.SetAmbientColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
170 aMatAspect.SetDiffuseColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
171 aMatAspect.SetEmissiveColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
172 aMatAspect.SetSpecularColor( Quantity_Color (Graphic3d_Vec3( 0.5f ) ) );
174 aMatAspect.SetAmbient( 0.5 );
175 aMatAspect.SetDiffuse( 0.5 );
176 aMatAspect.SetEmissive( 0.5 );
177 aMatAspect.SetSpecular( 0.5 );
179 aMatAspect.SetShininess(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 Standard_Boolean GEOM_AISShape::AcceptDisplayMode(const Standard_Integer theMode) const
223 return theMode >= Wireframe && theMode <= CustomHighlight;
226 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
227 const Handle(Prs3d_Presentation)& aPrs,
228 const Standard_Integer aMode)
230 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
232 Handle(AIS_InteractiveContext) anIC = GetContext();
233 // AKL: use old behavior to avoid keeping object's wireframe
234 // if to change shape properties (for example: 'Clear Top Level State','Color', 'Isos')
235 // calling popup menu over(!) the shape in OCC viewer.
236 anIC->SetToHilightSelected( false );
238 bool anIsField = !myFieldStepData.isEmpty();
239 bool anIsColorField = anIsField && myFieldDataType != GEOM::FDT_String;
240 bool anIsTextField = anIsField && myFieldDataType == GEOM::FDT_String;
242 if (isShowVertices())
243 myDrawer->SetVertexDrawMode(Prs3d_VDM_All);
245 // StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
246 bool isTopLev = isTopLevel() && switchTopLevel();
249 // Begin 0023271: [CEA 1823] Deflection Coefficient not taken into account in wireframe
251 StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
253 #if OCC_VERSION_LARGE <= 0x07040000
254 // After this call if type of deflection is relative
255 // computed deflection coefficient is stored as absolute.
256 Prs3d::GetDeflection (myshape, myDrawer);
260 case CustomHighlight:
263 SetColor(topLevelColor());
264 Handle(Prs3d_LineAspect) anAspect = Attributes()->WireAspect();
265 anAspect->SetColor( topLevelColor() );
266 Attributes()->SetWireAspect( anAspect );
268 if( !isTopLev && anIsColorField && myFieldDimension == 1 )
269 drawField( aPrs, false, aMode == CustomHighlight );
271 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
276 shadingMode(aPresentationManager, aPrs, aMode);
279 case ShadingWithEdges:
281 myDrawer->SetFaceBoundaryDraw( Standard_True );
282 shadingMode(aPresentationManager, aPrs, Shading);
283 if( anIsColorField && myFieldDimension == 1 ) {
284 myDrawer->SetFaceBoundaryDraw( Standard_False );
291 shadingMode(aPresentationManager, aPrs, Shading);
297 const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
298 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
299 for ( ; Exp.More(); Exp.Next() ) {
300 TopoDS_Vertex aV1, aV2;
301 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
303 // draw curve direction (issue 0021087)
304 anEdgeE.Orientation( TopAbs_FORWARD );
306 if ( anEdgeE.IsNull() ) continue;
308 TopExp::Vertices(anEdgeE, aV1, aV2);
309 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
310 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
314 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
316 if ( C.IsNull() ) continue;
318 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
319 C->D1(lp, aP2, aDirVec);
321 C->D1(fp, aP1, aDirVec);
325 GeomAdaptor_Curve aAdC;
326 aAdC.Load(C, fp, lp);
327 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
329 if (aDist > gp::Resolution()) {
331 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
336 Prs3d_Arrow::Draw(aPrs->CurrentGroup(), aP2, aDir, M_PI/180.*5., aDist/10.);
341 // draw color field on vertices
342 if( anIsColorField && myFieldDimension == 0 && aMode != CustomHighlight )
347 drawField( aPrs, true );
352 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
355 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
357 myShadingColor = aCol;
360 void GEOM_AISShape::SetEdgesInShadingColor(const Quantity_Color &aCol)
362 myEdgesInShadingColor = aCol;
365 void GEOM_AISShape::SetLabelColor(const Quantity_Color &aCol)
370 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
371 const Standard_Boolean aHighlight )
373 Handle(AIS_InteractiveObject) anObj = this;
374 Handle(AIS_InteractiveContext) anIC = GetContext();
378 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
379 anIC->SetAutomaticHilight( false );
381 anIC->ClearSelected( false );
384 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
386 // Get entity owners for all activated selection modes
387 getEntityOwners( anObj, anIC, anAllMap );
389 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
390 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
393 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
394 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
397 anIC->SetAutomaticHilight( isAutoHilight );
398 anIC->HilightSelected( false );
401 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
403 myDisplayVectors = isDisplayed;
406 void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
408 myDisplayVertices = isDisplayed;
411 void GEOM_AISShape::SetDisplayName(bool isDisplayed)
413 myDisplayName = isDisplayed;
416 void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
417 const Handle(Prs3d_Presentation)& aPrs,
418 const Standard_Integer aMode)
420 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
422 Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
423 aMatAspect.SetTransparency(Transparency());
424 Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
425 Graphic3d_MaterialAspect currentBackMaterial = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
426 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
427 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial );
429 if( isTopLevel() && switchTopLevel() )
430 myDrawer->ShadingAspect()->SetColor( topLevelColor() );
432 if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
433 myDrawer->ShadingAspect()->SetColor(myShadingColor);
435 myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
438 bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
439 if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
445 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
446 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
447 SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
451 Standard_Boolean GEOM_AISShape::isTopLevel()
456 void GEOM_AISShape::setTopLevel(Standard_Boolean f)
460 myPrevDisplayMode = DisplayMode();
462 switch(topLevelDisplayMode()) {
463 case TopWireFrame : dm = Wireframe; break;
464 case TopShading : dm = Shading; break;
465 case TopShadingWithEdges : dm = ShadingWithEdges; break;
466 default : dm = myPrevDisplayMode; break;
471 SetDisplayMode(myPrevDisplayMode);
476 void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
478 myPrevDisplayMode = mode;
481 Quantity_Color GEOM_AISShape::topLevelColor()
483 return myTopLevelColor;
486 void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
491 GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
496 void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
501 Standard_Boolean GEOM_AISShape::switchTopLevel()
503 return myTopLevelDm != TopShowAdditionalWActor;
506 Standard_Boolean GEOM_AISShape::toActivate()
508 return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
511 void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
512 const int theFieldDimension,
513 const QList<QVariant>& theFieldStepData,
514 const TCollection_AsciiString& theFieldStepName,
515 const double theFieldStepRangeMin,
516 const double theFieldStepRangeMax )
518 myFieldDataType = theFieldDataType;
519 myFieldDimension = theFieldDimension;
520 myFieldStepData = theFieldStepData;
521 myFieldStepName = theFieldStepName;
522 myFieldStepRangeMin = theFieldStepRangeMin;
523 myFieldStepRangeMax = theFieldStepRangeMax;
526 void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
527 int& theFieldDimension,
528 QList<QVariant>& theFieldStepData,
529 TCollection_AsciiString& theFieldStepName,
530 double& theFieldStepRangeMin,
531 double& theFieldStepRangeMax ) const
533 theFieldDataType = myFieldDataType;
534 theFieldDimension = myFieldDimension;
535 theFieldStepData = myFieldStepData;
536 theFieldStepName = myFieldStepName;
537 theFieldStepRangeMin = myFieldStepRangeMin;
538 theFieldStepRangeMax = myFieldStepRangeMax;
541 void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
542 const bool theIsString,
543 const bool theIsHighlight )
545 if( myFieldStepData.isEmpty() )
548 QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
550 TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
551 switch( myFieldDimension )
553 case 0: aShapeType = TopAbs_VERTEX; break;
554 case 1: aShapeType = TopAbs_EDGE; break;
555 case 2: aShapeType = TopAbs_FACE; break;
556 case 3: aShapeType = TopAbs_SOLID; break;
557 case -1: aShapeType = TopAbs_VERTEX; break;
560 TopTools_IndexedMapOfShape aShapeMap;
561 TopExp::MapShapes( myshape, aShapeMap );
563 TColStd_IndexedMapOfInteger anIndexMap;
565 TopExp_Explorer anExp;
566 for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
568 TopoDS_Shape aSubShape = anExp.Current();
569 if( !aSubShape.IsNull() )
571 Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
572 if( anIndexMap.Contains( aSubShapeIndex ) )
575 anIndexMap.Add( aSubShapeIndex );
577 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
581 if( aFieldStepDataIter.hasNext() )
583 const QVariant& aVariant = aFieldStepDataIter.next();
585 aString = aVariant.toString();
587 aQColor = aVariant.value<QColor>();
595 if( computeMassCenter( aSubShape, aCenter ) )
597 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
598 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
599 anAspectText3d->SetColor( myLabelColor );
600 aGroup->SetPrimitivesAspect( anAspectText3d );
602 #if OCC_VERSION_LARGE >= 0x070400ff
603 Handle(Graphic3d_Text) aText = new Graphic3d_Text (14.);
604 aText->SetText (aString.toUtf8().constData());
605 aText->SetPosition (aCenter);
606 aGroup->AddText (aText);
608 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
609 aGroup->Text( aString.toUtf8().constData(), aVertex, 14 ); // deprecated API, to be removed (see above)
615 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
616 SetCustomColor( aSubShape, aColor );
617 if( myFieldDimension == 0 )
619 TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
620 if( !aVertexShape.IsNull() )
622 gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
624 Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
625 anAspectMarker3d->SetColor( aColor );
626 anAspectMarker3d->SetType( Aspect_TOM_POINT );
627 anAspectMarker3d->SetScale( 10.0 );
628 aGroup->SetPrimitivesAspect( anAspectMarker3d );
630 Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
631 anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
633 aGroup->AddPrimitiveArray( anArray );
636 else if( myFieldDimension == 1 )
638 myDrawer->WireAspect()->SetColor( aColor );
640 myDrawer->WireAspect()->SetWidth( myOwnWidth );
642 myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
644 StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
647 else if( myFieldDimension == 2 ||
648 myFieldDimension == 3 ||
649 myFieldDimension == -1 )
651 //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
652 //anAspect->SetColor( aColor );
653 //myDrawer->SetShadingAspect( anAspect );
654 //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
660 SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
661 thePrs, AIS_Shaded );
664 void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
666 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
668 gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
669 gp_Pnt aCenter = anAx3.Location();
671 Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
672 anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
673 anAspectText3d->SetColor( myLabelColor );
674 aGroup->SetPrimitivesAspect( anAspectText3d );
676 const char* aName = getIO()->getName();
677 #if OCC_VERSION_LARGE >= 0x070400ff
678 Handle(Graphic3d_Text) aText = new Graphic3d_Text (16.);
679 aText->SetText (aName);
680 aText->SetPosition (aCenter);
681 aGroup->AddText(aText);
683 Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
684 aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 ); // deprecated API, to be removed (see above)
688 Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
691 theCenter.SetCoord( 0,0,0 );
692 Standard_Integer aNbPoints = 0;
694 if ( theShape.ShapeType() == TopAbs_EDGE )
697 Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
698 if ( !curve.IsNull() )
700 theCenter = curve->Value( 0.5 * ( f + l ));
704 else if ( theShape.ShapeType() == TopAbs_FACE )
706 const TopoDS_Face& F = TopoDS::Face( theShape );
707 BRepAdaptor_Surface surface( F );
710 Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
711 if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
715 const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
716 const Poly_Array1OfTriangle& trias = triangulation->Triangles();
717 Standard_Integer n1,n2,n3;
718 for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
720 trias( iT ).Get( n1,n2,n3 );
721 const gp_Pnt2d& uv1 = uvArray( n1 );
722 const gp_Pnt2d& uv2 = uvArray( n2 );
723 const gp_Pnt2d& uv3 = uvArray( n3 );
724 double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
725 ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
726 C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
729 if ( A > std::numeric_limits<double>::min() )
732 theCenter = surface.Value( C.X(), C.Y() );
736 if ( aNbPoints == 0 )
738 theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
739 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
744 if ( aNbPoints == 0 )
746 TopExp_Explorer anExp;
747 for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
749 TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
750 if( !aVertex.IsNull() )
752 gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
753 theCenter.ChangeCoord() += aPnt.XYZ();
760 theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;