// Created on: 2000-08-11 // Created by: Andrey BETENEV // Copyright (c) 2000-2012 OPEN CASCADE SAS // // The content of this file is subject to the Open CASCADE Technology Public // License Version 6.5 (the "License"). You may not use the content of this file // except in compliance with the License. Please obtain a copy of the License // at http://www.opencascade.org and read it completely before using this file. // // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. // // The Original Code and all software distributed under the License is // distributed on an "AS IS" basis, without warranty of any kind, and the // Initial Developer hereby disclaims all such warranties, including without // limitation, any warranties of merchantability, fitness for a particular // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEBUG #include #endif //======================================================================= //function : XCAFPrs_AISObject //purpose : //======================================================================= XCAFPrs_AISObject::XCAFPrs_AISObject (const TDF_Label &lab) : AIS_Shape(TopoDS_Shape()) { myLabel = lab; TopoDS_Shape shape; if ( XCAFDoc_ShapeTool::GetShape ( myLabel, shape ) && ! shape.IsNull() ) Set ( shape ); } //======================================================================= //function : SetColor //purpose : //======================================================================= void XCAFPrs_AISObject::SetColor(const Quantity_Color &aCol) { AIS_Shape::SetColor(aCol); LoadRecomputable(1); } //======================================================================= //function : UnsetColor //purpose : //======================================================================= void XCAFPrs_AISObject::UnsetColor() { if (HasColor()) { AIS_Shape::UnsetColor(); LoadRecomputable(1); } else { myToRecomputeModes.Clear(); } } //======================================================================= //function : SetMaterial //purpose : //======================================================================= void XCAFPrs_AISObject::SetMaterial(const Graphic3d_NameOfMaterial aMat) { AIS_Shape::SetMaterial(aMat); LoadRecomputable(1); } //======================================================================= //function : SetMaterial //purpose : //======================================================================= void XCAFPrs_AISObject::SetMaterial(const Graphic3d_MaterialAspect& aMat) { AIS_Shape::SetMaterial(aMat); LoadRecomputable(1); } //======================================================================= //function : UnsetMaterial //purpose : //======================================================================= void XCAFPrs_AISObject::UnsetMaterial() { if (HasMaterial()) { AIS_Shape::UnsetMaterial(); LoadRecomputable(1); } else { myToRecomputeModes.Clear(); } } //======================================================================= //function : SetTransparency //purpose : //======================================================================= void XCAFPrs_AISObject::SetTransparency(const Standard_Real AValue) { AIS_Shape::SetTransparency(AValue); LoadRecomputable(1); } //======================================================================= //function : UnsetTransparency //purpose : //======================================================================= void XCAFPrs_AISObject::UnsetTransparency() { AIS_Shape::UnsetTransparency(); LoadRecomputable(1); } //======================================================================= //function : AddStyledItem //purpose : //======================================================================= void XCAFPrs_AISObject::AddStyledItem (const XCAFPrs_Style &style, const TopoDS_Shape &shape, const Handle(PrsMgr_PresentationManager3d)&, // aPresentationManager, const Handle(Prs3d_Presentation)& aPrs, const Standard_Integer aMode) { // remember current color settings Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect(); Aspect_InteriorStyle aStyle; Quantity_Color aIntColor, aEdgeColor; Aspect_TypeOfLine aType; Standard_Real aWidth; a4bis->Values(aStyle,aIntColor,aEdgeColor,aType,aWidth); Graphic3d_MaterialAspect FMAT = a4bis->FrontMaterial(); Quantity_Color aFColor = FMAT.Color(); Quantity_Color aColor1, aColor2; Aspect_TypeOfLine aLine1, aLine2; Standard_Real aWigth1, aWigth2; Handle(Prs3d_LineAspect) waUFB = myDrawer->UnFreeBoundaryAspect(); waUFB->Aspect()->Values(aColor1,aLine1,aWigth1); Handle(Prs3d_LineAspect) waFB = myDrawer->FreeBoundaryAspect(); waFB->Aspect()->Values(aColor2,aLine2,aWigth2); Quantity_Color aColor; Aspect_TypeOfLine aLine; Standard_Real aWigth; Handle(Prs3d_LineAspect) wa = myDrawer->WireAspect(); wa->Aspect()->Values(aColor,aLine,aWigth); Quantity_Color aColorU, aColorV; Aspect_TypeOfLine aLineU, aLineV; Standard_Real aWigthU, aWigthV; Handle(Prs3d_IsoAspect) UIso = myDrawer->UIsoAspect(); Handle(Prs3d_IsoAspect) VIso = myDrawer->VIsoAspect(); UIso->Aspect()->Values(aColorU,aLineU,aWigthU); VIso->Aspect()->Values(aColorV,aLineV,aWigthV); // Set colors etc. for current shape according to style if ( style.IsSetColorCurv() ) { Quantity_Color Color = style.GetColorCurv(); waUFB->SetColor ( Color.Name() ); waFB->SetColor ( Color.Name() ); wa->SetColor ( Color.Name() ); } if ( style.IsSetColorSurf() ) { Quantity_Color Color = style.GetColorSurf(); a4bis->SetInteriorColor(Color); FMAT.SetColor(Color); a4bis->SetFrontMaterial(FMAT); UIso->SetColor ( Color.Name() ); VIso->SetColor ( Color.Name() ); } // force drawing isos on planes Standard_Boolean drawIsosPln = myDrawer->IsoOnPlane(); myDrawer->SetIsoOnPlane (Standard_True); // add shape to presentation switch (aMode) { case 0:{ try { OCC_CATCH_SIGNALS StdPrs_WFDeflectionShape::Add(aPrs,shape,myDrawer); } catch (Standard_Failure) { #ifdef DEB cout << "AIS_Shape::Compute() failed: exception " << Standard_Failure::Caught()->DynamicType()->Name() << ": " << Standard_Failure::Caught()->GetMessageString() << endl; #endif // cout << "a Shape should be incorrect: No Compute can be maked on it "<< endl; // on calcule une presentation de la boite englobante // Compute(aPresentationManager,aPrs,2); } break; } case 1: { Standard_Real prevangle ; Standard_Real newangle ; Standard_Real prevcoeff ; Standard_Real newcoeff ; if (OwnDeviationAngle(newangle,prevangle) || OwnDeviationCoefficient(newcoeff,prevcoeff)) if (Abs (newangle - prevangle) > Precision::Angular() || Abs (newcoeff - prevcoeff) > Precision::Confusion() ) { #ifdef DEB cout << "AIS_Shape : compute"<4) StdPrs_WFDeflectionShape::Add(aPrs,shape,myDrawer); else { myDrawer->SetShadingAspectGlobal(Standard_False); if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,shape,myDrawer); else StdPrs_ShadedShape::Add(aPrs,shape,myDrawer); } } catch (Standard_Failure) { #ifdef DEB cout << "AIS_Shape::Compute() in ShadingMode failed: exception " << Standard_Failure::Caught()->DynamicType()->Name() << ": " << Standard_Failure::Caught()->GetMessageString() << endl; #endif // last resort: try to display as wireframe try { OCC_CATCH_SIGNALS StdPrs_WFShape::Add(aPrs,shape,myDrawer); } catch (Standard_Failure) { } } break; } case 2: { // boite englobante if (IsInfinite()) StdPrs_WFDeflectionShape::Add(aPrs,shape,myDrawer); else DisplayBox(aPrs,BoundingBox(),myDrawer); } } // Restore initial settings if ( style.IsSetColorCurv() ) { waUFB->SetColor ( aColor1.Name() ); waFB->SetColor ( aColor2.Name() ); wa->SetColor ( aColor.Name() ); } if ( style.IsSetColorSurf() ) { a4bis->SetInteriorColor(aIntColor); FMAT.SetColor(aFColor); a4bis->SetFrontMaterial(FMAT); UIso->SetColor ( aColorU ); VIso->SetColor ( aColorV ); } myDrawer->SetIsoOnPlane (drawIsosPln); } //======================================================================= //function : DisplayText //purpose : //======================================================================= static void DisplayText (const TDF_Label& aLabel, const Handle(Prs3d_Presentation)& aPrs, const Handle(Prs3d_TextAspect)& anAspect, const TopLoc_Location& aLocation) { // first label itself Handle (TDataStd_Name) aName; if (aLabel.FindAttribute (TDataStd_Name::GetID(), aName)) { TopoDS_Shape aShape; if (XCAFDoc_ShapeTool::GetShape (aLabel, aShape)) { // find the position to display as middle of the bounding box aShape.Move (aLocation); Bnd_Box aBox; BRepBndLib::Add (aShape, aBox); if ( ! aBox.IsVoid() ) { Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; aBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); gp_Pnt aPnt (0.5 * (aXmin + aXmax), 0.5 * (aYmin + aYmax), 0.5 * (aZmin + aZmax)); Prs3d_Text::Draw( aPrs, anAspect, aName->Get(), aPnt); } } } TDF_LabelSequence seq; // attibutes of subshapes if (XCAFDoc_ShapeTool::GetSubShapes (aLabel, seq)) { Standard_Integer i = 1; for (i = 1; i <= seq.Length(); i++) { TDF_Label aL = seq.Value (i); DisplayText (aL, aPrs, anAspect, aLocation); //suppose that subshapes do not contain locations } } // attibutes of components seq.Clear(); if (XCAFDoc_ShapeTool::GetComponents (aLabel, seq)) { Standard_Integer i = 1; for (i = 1; i <= seq.Length(); i++) { TDF_Label aL = seq.Value (i); DisplayText (aL, aPrs, anAspect, aLocation); TDF_Label aRefLabel; // attributes of referrences TopLoc_Location aLoc = XCAFDoc_ShapeTool::GetLocation (aL); if (XCAFDoc_ShapeTool::GetReferredShape (aL, aRefLabel)) { DisplayText (aRefLabel, aPrs, anAspect, aLoc); } } } } //======================================================================= //function : Compute //purpose : //======================================================================= // The Compute() method is copied from AIS_Shape::Compute and enhanced to // support different color settings for different subshapes of a single shape void XCAFPrs_AISObject::Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, const Handle(Prs3d_Presentation)& aPrs, const Standard_Integer aMode) { #ifdef DEB //cout << "XCAFPrs_AISObject: Update called" << endl; #endif aPrs->Clear(); // abv: 06 Mar 00: to have good colors Handle(TPrsStd_AISPresentation) prs = Handle(TPrsStd_AISPresentation)::DownCast ( GetOwner() ); if ( prs.IsNull() || !prs->HasOwnMaterial() ) AIS_Shape::SetMaterial ( Graphic3d_NOM_PLASTIC ); TopoDS_Shape shape; if ( ! XCAFDoc_ShapeTool::GetShape ( myLabel, shape ) || shape.IsNull() ) return; // wire,edge,vertex -> pas de HLR + priorite display superieure Standard_Integer TheType = (Standard_Integer)shape.ShapeType(); if(TheType>4 && TheType<8) { aPrs->SetVisual(Graphic3d_TOS_ALL); aPrs->SetDisplayPriority(TheType+2); } // Shape vide -> Assemblage vide. if (shape.ShapeType() == TopAbs_COMPOUND) { TopoDS_Iterator anExplor (shape); if (!anExplor.More()) { return; } } if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL // collect information on colored subshapes TopLoc_Location L; XCAFPrs_DataMapOfShapeStyle settings; XCAFPrs::CollectStyleSettings ( myLabel, L, settings ); #ifdef DEB //cout << "Styles collected" << endl; #endif // dispatch (sub)shapes by their styles XCAFPrs_DataMapOfStyleShape items; XCAFPrs_Style DefStyle; Quantity_Color White ( Quantity_NOC_WHITE ); DefStyle.SetColorSurf ( White ); DefStyle.SetColorCurv ( White ); XCAFPrs::DispatchStyles ( shape, settings, items, DefStyle ); #ifdef DEB //cout << "Dispatch done" << endl; #endif // add subshapes to presentation (one shape per style) XCAFPrs_DataMapIteratorOfDataMapOfStyleShape it ( items ); #ifdef DEB //Standard_Integer i=1; #endif for ( ; it.More(); it.Next() ) { XCAFPrs_Style s = it.Key(); #ifdef DEB //cout << "Style " << i << ": [" << // ( s.IsSetColorSurf() ? Quantity_Color::StringName ( s.GetColorSurf().Name() ) : "" ) << ", " << // ( s.IsSetColorCurv() ? Quantity_Color::StringName ( s.GetColorCurv().Name() ) : "" ) << "]" << //" --> si_" << i << ( s.IsVisible() ? "" : " " ) << endl; //i++; #endif if (! s.IsVisible() ) continue; Prs3d_Root::NewGroup(aPrs); AddStyledItem ( s, it.Value(), aPresentationManager, aPrs, aMode ); } if ( XCAFPrs::GetViewNameMode() ) { // Displaying Name attributes #ifdef DEB //cout << "Now display name of shapes" << endl; #endif aPrs->SetDisplayPriority(10); DisplayText (myLabel, aPrs, Attributes()->LengthAspect()->TextAspect(), TopLoc_Location());//no location } #ifdef DEB //cout << "Compute finished" << endl; #endif aPrs->ReCompute(); // for hidden line recomputation if necessary... }