+
+void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
+{
+ myDisplayVectors = isDisplayed;
+}
+
+void GEOM_AISShape::SetDisplayVertices(bool isDisplayed)
+{
+ myDisplayVertices = isDisplayed;
+}
+
+void GEOM_AISShape::SetDisplayName(bool isDisplayed)
+{
+ myDisplayName = isDisplayed;
+}
+
+void GEOM_AISShape::shadingMode(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
+ const Handle(Prs3d_Presentation)& aPrs,
+ const Standard_Integer aMode)
+{
+ myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
+
+ Graphic3d_MaterialAspect aMatAspect(Graphic3d_NOM_PLASTIC);
+ aMatAspect.SetTransparency(Transparency());
+ Graphic3d_MaterialAspect currentFrontMaterial = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
+ Graphic3d_MaterialAspect currentBackMaterial = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
+ myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial( isTopLevel() ? aMatAspect : currentFrontMaterial );
+ myDrawer->ShadingAspect()->Aspect()->SetBackMaterial ( isTopLevel() ? aMatAspect : currentBackMaterial );
+
+ if( isTopLevel() && switchTopLevel() )
+ myDrawer->ShadingAspect()->SetColor( topLevelColor() );
+ else {
+ if(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().MaterialType( Graphic3d_MATERIAL_ASPECT ))
+ myDrawer->ShadingAspect()->SetColor(myShadingColor);
+ else
+ myDrawer->ShadingAspect()->SetColor(myDrawer->ShadingAspect()->Aspect()->FrontMaterial().AmbientColor());
+ }
+
+ bool anIsColorField = !myFieldStepData.isEmpty() && myFieldDataType != GEOM::FDT_String;
+ if( anIsColorField && ( myFieldDimension == 2 || myFieldDimension == 3 || myFieldDimension == -1 ) )
+ {
+ drawField( aPrs );
+ }
+ else
+ {
+ // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
+ //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
+ SALOME_AISShape::Compute(aPresentationManager, aPrs, aMode);
+ }
+}
+
+Standard_Boolean GEOM_AISShape::isTopLevel()
+{
+ return myTopLevel;
+}
+
+void GEOM_AISShape::setTopLevel(Standard_Boolean f)
+{
+ if(f) {
+ if(f != myTopLevel)
+ myPrevDisplayMode = DisplayMode();
+ Standard_Integer dm;
+ switch(topLevelDisplayMode()) {
+ case TopWireFrame : dm = Wireframe; break;
+ case TopShading : dm = Shading; break;
+ case TopShadingWithEdges : dm = ShadingWithEdges; break;
+ default : dm = myPrevDisplayMode; break;
+ }
+ SetDisplayMode(dm);
+ } else {
+ if(f != myTopLevel)
+ SetDisplayMode(myPrevDisplayMode);
+ }
+ myTopLevel = f;
+}
+
+void GEOM_AISShape::setPrevDisplayMode(const Standard_Integer mode)
+{
+ myPrevDisplayMode = mode;
+}
+
+Quantity_Color GEOM_AISShape::topLevelColor()
+{
+ return myTopLevelColor;
+}
+
+void GEOM_AISShape::setTopLevelColor(const Quantity_Color c)
+{
+ myTopLevelColor = c;
+}
+
+GEOM_AISShape::TopLevelDispMode GEOM_AISShape::topLevelDisplayMode()
+{
+ return myTopLevelDm;
+}
+
+void GEOM_AISShape::setTopLevelDisplayMode(const GEOM_AISShape::TopLevelDispMode dm)
+{
+ myTopLevelDm = dm;
+}
+
+Standard_Boolean GEOM_AISShape::switchTopLevel()
+{
+ return myTopLevelDm != TopShowAdditionalWActor;
+}
+
+Standard_Boolean GEOM_AISShape::toActivate()
+{
+ return ( myTopLevel && myTopLevelDm == TopShowAdditionalWActor ) ? false : true;
+}
+
+void GEOM_AISShape::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
+ const int theFieldDimension,
+ const QList<QVariant>& theFieldStepData,
+ const TCollection_AsciiString& theFieldStepName,
+ const double theFieldStepRangeMin,
+ const double theFieldStepRangeMax )
+{
+ myFieldDataType = theFieldDataType;
+ myFieldDimension = theFieldDimension;
+ myFieldStepData = theFieldStepData;
+ myFieldStepName = theFieldStepName;
+ myFieldStepRangeMin = theFieldStepRangeMin;
+ myFieldStepRangeMax = theFieldStepRangeMax;
+}
+
+void GEOM_AISShape::getFieldStepInfo( GEOM::field_data_type& theFieldDataType,
+ int& theFieldDimension,
+ QList<QVariant>& theFieldStepData,
+ TCollection_AsciiString& theFieldStepName,
+ double& theFieldStepRangeMin,
+ double& theFieldStepRangeMax ) const
+{
+ theFieldDataType = myFieldDataType;
+ theFieldDimension = myFieldDimension;
+ theFieldStepData = myFieldStepData;
+ theFieldStepName = myFieldStepName;
+ theFieldStepRangeMin = myFieldStepRangeMin;
+ theFieldStepRangeMax = myFieldStepRangeMax;
+}
+
+void GEOM_AISShape::drawField( const Handle(Prs3d_Presentation)& thePrs,
+ const bool theIsString,
+ const bool theIsHighlight )
+{
+ if( myFieldStepData.isEmpty() )
+ return;
+
+ QListIterator<QVariant> aFieldStepDataIter( myFieldStepData );
+
+ TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE;
+ switch( myFieldDimension )
+ {
+ case 0: aShapeType = TopAbs_VERTEX; break;
+ case 1: aShapeType = TopAbs_EDGE; break;
+ case 2: aShapeType = TopAbs_FACE; break;
+ case 3: aShapeType = TopAbs_SOLID; break;
+ case -1: aShapeType = TopAbs_VERTEX; break;
+ }
+
+ TopTools_IndexedMapOfShape aShapeMap;
+ TopExp::MapShapes( myshape, aShapeMap );
+
+ TColStd_IndexedMapOfInteger anIndexMap;
+
+ TopExp_Explorer anExp;
+ for( anExp.Init( myshape, aShapeType ); anExp.More(); anExp.Next() )
+ {
+ TopoDS_Shape aSubShape = anExp.Current();
+ if( !aSubShape.IsNull() )
+ {
+ Standard_Integer aSubShapeIndex = aShapeMap.FindIndex( aSubShape );
+ if( anIndexMap.Contains( aSubShapeIndex ) )
+ continue;
+
+ anIndexMap.Add( aSubShapeIndex );
+
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
+
+ QColor aQColor;
+ QString aString;
+ if( aFieldStepDataIter.hasNext() )
+ {
+ const QVariant& aVariant = aFieldStepDataIter.next();
+ if( theIsString )
+ aString = aVariant.toString();
+ else
+ aQColor = aVariant.value<QColor>();
+ }
+ else
+ break;
+
+ if( theIsString )
+ {
+ gp_Pnt aCenter;
+ if( computeMassCenter( aSubShape, aCenter ) )
+ {
+ Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
+
+ Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
+ anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
+ anAspectText3d->SetColor( myLabelColor );
+ aGroup->SetPrimitivesAspect( anAspectText3d );
+
+ aGroup->Text( aString.toUtf8().constData(), aVertex, 14 );
+ }
+ }
+ else
+ {
+ Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
+ SetCustomColor( aSubShape, aColor );
+ if( myFieldDimension == 0 )
+ {
+ TopoDS_Vertex aVertexShape = TopoDS::Vertex( aSubShape );
+ if( !aVertexShape.IsNull() )
+ {
+ gp_Pnt aPnt = BRep_Tool::Pnt( aVertexShape );
+
+ Handle(Graphic3d_AspectMarker3d) anAspectMarker3d = new Graphic3d_AspectMarker3d();
+ anAspectMarker3d->SetColor( aColor );
+ anAspectMarker3d->SetType( Aspect_TOM_POINT );
+ anAspectMarker3d->SetScale( 10.0 );
+ aGroup->SetPrimitivesAspect( anAspectMarker3d );
+
+ Handle(Graphic3d_ArrayOfPoints) anArray = new Graphic3d_ArrayOfPoints( 1 );
+ anArray->AddVertex( aPnt.X(), aPnt.Y(), aPnt.Z() );
+
+ aGroup->AddPrimitiveArray( anArray );
+ }
+ }
+ else if( myFieldDimension == 1 )
+ {
+ myDrawer->WireAspect()->SetColor( aColor );
+ if( theIsHighlight )
+ myDrawer->WireAspect()->SetWidth( myOwnWidth );
+ else
+ myDrawer->WireAspect()->SetWidth( myOwnWidth + 4 );
+ /*
+ StdPrs_WFShape::Add( thePrs, aSubShape, myDrawer );
+ */
+ }
+ else if( myFieldDimension == 2 ||
+ myFieldDimension == 3 ||
+ myFieldDimension == -1 )
+ {
+ //Handle(Prs3d_ShadingAspect) anAspect = new Prs3d_ShadingAspect();
+ //anAspect->SetColor( aColor );
+ //myDrawer->SetShadingAspect( anAspect );
+ //StdPrs_ShadedShape::Add( thePrs, aSubShape, myDrawer );
+ }
+ }
+ }
+ }
+
+ SALOME_AISShape::Compute( Handle(PrsMgr_PresentationManager3d)(),
+ thePrs, AIS_Shaded );
+}
+
+void GEOM_AISShape::drawName( const Handle(Prs3d_Presentation)& thePrs )
+{
+ Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup( thePrs );
+
+ gp_Ax3 anAx3 = GEOMUtils::GetPosition(myshape);
+ gp_Pnt aCenter = anAx3.Location();
+
+ Graphic3d_Vertex aVertex( aCenter.X(), aCenter.Y(), aCenter.Z() );
+
+ Handle(Graphic3d_AspectText3d) anAspectText3d = new Graphic3d_AspectText3d();
+ anAspectText3d->SetStyle( Aspect_TOST_ANNOTATION );
+ anAspectText3d->SetColor( myLabelColor );
+ aGroup->SetPrimitivesAspect( anAspectText3d );
+
+ const char* aName = getIO()->getName();
+ aGroup->Text( TCollection_ExtendedString( aName ), aVertex, 16 );
+}
+
+Standard_Boolean GEOM_AISShape::computeMassCenter( const TopoDS_Shape& theShape,
+ gp_Pnt& theCenter )
+{
+ theCenter.SetCoord( 0,0,0 );
+ Standard_Integer aNbPoints = 0;
+
+ if ( theShape.ShapeType() == TopAbs_EDGE )
+ {
+ double f,l;
+ Handle(Geom_Curve) curve = BRep_Tool::Curve( TopoDS::Edge( theShape ), f, l );
+ if ( !curve.IsNull() )
+ {
+ theCenter = curve->Value( 0.5 * ( f + l ));
+ aNbPoints = 1;
+ }
+ }
+ else if ( theShape.ShapeType() == TopAbs_FACE )
+ {
+ const TopoDS_Face& F = TopoDS::Face( theShape );
+ BRepAdaptor_Surface surface( F );
+
+ TopLoc_Location L;
+ Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation( F, L );
+ if ( !triangulation.IsNull() && triangulation->HasUVNodes() )
+ {
+ gp_XY C( 0, 0 );
+ double A = 0;
+ const TColgp_Array1OfPnt2d& uvArray = triangulation->UVNodes();
+ const Poly_Array1OfTriangle& trias = triangulation->Triangles();
+ Standard_Integer n1,n2,n3;
+ for ( int iT = trias.Lower(); iT <= trias.Upper(); ++iT )
+ {
+ trias( iT ).Get( n1,n2,n3 );
+ const gp_Pnt2d& uv1 = uvArray( n1 );
+ const gp_Pnt2d& uv2 = uvArray( n2 );
+ const gp_Pnt2d& uv3 = uvArray( n3 );
+ double a = 0.5 * sqrt(( uv1.X() - uv3.X() ) * ( uv2.Y() - uv1.Y() ) -
+ ( uv1.X() - uv2.X() ) * ( uv3.Y() - uv1.Y() ));
+ C += ( uv1.XY() + uv2.XY() + uv3.XY() ) / 3. * a;
+ A += a;
+ }
+ if ( A > std::numeric_limits<double>::min() )
+ {
+ C /= A;
+ theCenter = surface.Value( C.X(), C.Y() );
+ aNbPoints = 1;
+ }
+ }
+ if ( aNbPoints == 0 )
+ {
+ theCenter = surface.Value( 0.5 * ( surface.FirstUParameter() + surface.LastUParameter() ),
+ 0.5 * ( surface.FirstVParameter() + surface.LastVParameter() ));
+ }
+ aNbPoints = 1;
+ }
+
+ if ( aNbPoints == 0 )
+ {
+ TopExp_Explorer anExp;
+ for( anExp.Init( theShape, TopAbs_VERTEX ); anExp.More(); anExp.Next() )
+ {
+ TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
+ if( !aVertex.IsNull() )
+ {
+ gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
+ theCenter.ChangeCoord() += aPnt.XYZ();
+ aNbPoints++;
+ }
+ }
+ }
+
+ if ( aNbPoints > 0 )
+ theCenter.ChangeCoord() /= (Standard_Real) aNbPoints;
+
+ return aNbPoints;
+}