1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

89
src/XCAFPrs/XCAFPrs.cdl Executable file
View File

@@ -0,0 +1,89 @@
-- File: XCAFPrs.cdl
-- Created: Fri Aug 11 16:28:46 2000
-- Author: Andrey BETENEV
-- <abv@doomox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2000
package XCAFPrs
---Purpose: Presentation (visualiation, selection etc.) tools for
-- DECAF documents
uses
Quantity,
TCollection,
TopAbs,
TopLoc,
TopoDS,
TopTools,
Prs3d,
PrsMgr,
TPrsStd,
AIS,
TDF,
XCAFDoc
is
class Driver;
---Purpose: Implements a presentation driver for DECAF
class AISObject;
---Purpose: Implements an interactive object for DECAF
class Style;
---Purpose: Object representing a set of style settings
class DataMapOfShapeStyle instantiates
DataMap from TCollection(Shape from TopoDS,
Style from XCAFPrs,
ShapeMapHasher from TopTools);
class DataMapOfStyleShape instantiates
DataMap from TCollection(Style from XCAFPrs,
Shape from TopoDS,
Style from XCAFPrs);
class DataMapOfStyleTransient instantiates
DataMap from TCollection(Style from XCAFPrs,
Transient from Standard,
Style from XCAFPrs);
---Methods: Work with styles of the document
CollectStyleSettings (L: Label from TDF;
loc: Location from TopLoc;
settings: in out DataMapOfShapeStyle from XCAFPrs);
---Purpose: Collect styles defined for shape on label L
-- and its components and subshapes and fills a map of
-- shape - style correspondence
-- The location <loc> is for internal use, it
-- should be Null location for external call
DispatchStyles (shape: Shape from TopoDS;
settings: DataMapOfShapeStyle from XCAFPrs;
items: in out DataMapOfStyleShape from XCAFPrs;
DefStyle: Style from XCAFPrs;
force: Boolean = Standard_True;
context: ShapeEnum from TopAbs = TopAbs_SHAPE)
returns Boolean;
---Purpose: Iterates on shape (recursively) and splits it
-- on parts each of which has its own style
-- (basing on settings collected by CollectStyleSettings())
-- The DefStyle is default style applied to a shape if
-- no specific style assignment is applied to it
-- If force is True, the <shape> is added to a map
-- even if no styles are redefined for it or its
-- subshapes
-- The context is for internal use, it indicates
-- the type of the shape to which <shape> belongs
SetViewNameMode ( viewNameMode: Boolean from Standard);
---Purpose: Set ViewNameMode for indicate display names or not.
GetViewNameMode returns Boolean;
end XCAFPrs;

291
src/XCAFPrs/XCAFPrs.cxx Executable file
View File

@@ -0,0 +1,291 @@
// File: XCAFPrs.cxx
// Created: Tue Aug 15 19:37:35 2000
// Author: Andrey BETENEV
// <abv@doomox.nnov.matra-dtv.fr>
#include <XCAFPrs.ixx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_ColorTool.hxx>
#include <TDF_LabelSequence.hxx>
#include <TopoDS_Iterator.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <TColStd_HSequenceOfExtendedString.hxx>
#include <XCAFDoc_LayerTool.hxx>
#include <TopTools_SequenceOfShape.hxx>
#include <TopLoc_IndexedMapOfLocation.hxx>
#include <TDF_AttributeSequence.hxx>
#include <XCAFDoc_GraphNode.hxx>
static Standard_Boolean viewnameMode = Standard_False;
static Standard_Boolean getShapesOfSHUO (TopLoc_IndexedMapOfLocation& theaPrevLocMap,
const Handle(XCAFDoc_ShapeTool)& theSTool,
const TDF_Label& theSHUOlab,
TopTools_SequenceOfShape& theSHUOShapeSeq)
{
Handle(XCAFDoc_GraphNode) SHUO;
TDF_LabelSequence aLabSeq;
theSTool->GetSHUONextUsage( theSHUOlab, aLabSeq );
if (aLabSeq.Length() >= 1)
for (Standard_Integer i = 1; i <= aLabSeq.Length(); i++) {
TDF_Label aSubCompL = aLabSeq.Value( i );
TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation ( aSubCompL.Father() );
// create new map of laocation (to not merge locations from different shapes)
TopLoc_IndexedMapOfLocation aNewPrevLocMap;
for (Standard_Integer m = 1; m <= theaPrevLocMap.Extent(); m++)
aNewPrevLocMap.Add( theaPrevLocMap.FindKey( m ) );
aNewPrevLocMap.Add( compLoc );
// got for the new sublocations and corresponding shape
getShapesOfSHUO( aNewPrevLocMap, theSTool, aSubCompL, theSHUOShapeSeq );
}
else {
TopoDS_Shape aSHUO_NUSh = theSTool->GetShape ( theSHUOlab.Father() );
if ( aSHUO_NUSh.IsNull() ) return Standard_False;
// cause got shape with location already.
TopLoc_Location nullLoc;
aSHUO_NUSh.Location ( nullLoc );
// multiply the locations
Standard_Integer intMapLenght = theaPrevLocMap.Extent();
if ( intMapLenght < 1 )
return Standard_False; // should not be, but to avoid exception...?
TopLoc_Location SupcompLoc;
SupcompLoc = theaPrevLocMap.FindKey( intMapLenght );
if (intMapLenght > 1) {
Standard_Integer l = intMapLenght - 1;
while (l >= 1) {
SupcompLoc = theaPrevLocMap.FindKey( l ).Multiplied( SupcompLoc );
l--;
}
}
aSHUO_NUSh.Location( SupcompLoc );
theSHUOShapeSeq.Append( aSHUO_NUSh );
}
return (theSHUOShapeSeq.Length() > 0);
}
//=======================================================================
//function : CollectStyleSettings
//purpose :
//=======================================================================
void XCAFPrs::CollectStyleSettings (const TDF_Label &L,
const TopLoc_Location &loc,
XCAFPrs_DataMapOfShapeStyle &settings)
{
Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( L );
// for references, first collect colors of referred shape
TDF_Label Lref;
if ( XCAFDoc_ShapeTool::GetReferredShape ( L, Lref ) ) {
TopLoc_Location locSub = loc.Multiplied ( XCAFDoc_ShapeTool::GetLocation ( L ) );
CollectStyleSettings ( Lref, locSub, settings );
}
// for assemblies, first collect colors defined in components
TDF_LabelSequence seq;
if ( XCAFDoc_ShapeTool::GetComponents ( L, seq ) && seq.Length() >0 ) {
for ( Standard_Integer i = 1; i <= seq.Length(); i++ ) {
CollectStyleSettings ( seq.Value(i), loc, settings );
}
}
// collect settings on subshapes and the shape itself
seq.Clear();
XCAFDoc_ShapeTool::GetSubShapes ( L, seq );
seq.Append ( L );
for ( Standard_Integer i = 1; i <= seq.Length(); i++ ) {
TDF_Label lab = seq.Value(i);
XCAFPrs_Style style;
Handle(XCAFDoc_LayerTool) LTool = XCAFDoc_DocumentTool::LayerTool( lab );
Handle(TColStd_HSequenceOfExtendedString) LayNames = new TColStd_HSequenceOfExtendedString;
LTool->GetLayers(lab, LayNames);
Standard_Integer InVisCount = 0;
for ( Standard_Integer iL = 1; iL <= LayNames->Length(); iL++) {
if ( !LTool->IsVisible( LTool->FindLayer(LayNames->Value(iL)) ) ) InVisCount++;
}
if ( InVisCount >0 && InVisCount == LayNames->Length() ||
!CTool->IsVisible(lab) ) {
style.SetVisibility(Standard_False);
}
else {
Quantity_Color C;
if ( CTool->GetColor ( lab, XCAFDoc_ColorGen, C ) ) {
style.SetColorCurv ( C );
style.SetColorSurf ( C );
}
if ( CTool->GetColor ( lab, XCAFDoc_ColorSurf, C ) )
style.SetColorSurf ( C );
if ( CTool->GetColor ( lab, XCAFDoc_ColorCurv, C ) )
style.SetColorCurv ( C );
}
// PTV try to set color from SHUO structure
Handle(XCAFDoc_ShapeTool) STool = CTool->ShapeTool();
Handle(XCAFDoc_GraphNode) SHUO;
TDF_AttributeSequence theSHUOAttrs;
if (STool->IsComponent( lab ) ) {
STool->GetAllComponentSHUO( lab, theSHUOAttrs );
for (Standard_Integer shuoIndx = 1; shuoIndx <= theSHUOAttrs.Length(); shuoIndx++) {
SHUO = Handle(XCAFDoc_GraphNode)::DownCast(theSHUOAttrs.Value(shuoIndx));
if ( SHUO.IsNull() )
continue;
TDF_Label aSHUOlab = SHUO->Label();
TDF_LabelSequence aLabSeq;
STool->GetSHUONextUsage( aSHUOlab, aLabSeq );
if (aLabSeq.Length() < 1 )
continue;
Quantity_Color C;
XCAFPrs_Style SHUOstyle;
if (!CTool->IsVisible( aSHUOlab ) )
SHUOstyle.SetVisibility(Standard_False);
else {
if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorGen, C ) ) {
SHUOstyle.SetColorCurv ( C );
SHUOstyle.SetColorSurf ( C );
}
if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorSurf, C ) )
SHUOstyle.SetColorSurf ( C );
if ( CTool->GetColor ( aSHUOlab, XCAFDoc_ColorCurv, C ) )
SHUOstyle.SetColorCurv ( C );
}
if ( !SHUOstyle.IsSetColorCurv() &&
!SHUOstyle.IsSetColorSurf() &&
SHUOstyle.IsVisible() )
continue;
// set style for all component from Next Usage Occurrence.
#ifdef DEB
cout << "Set the style for SHUO next_usage-occurrance" << endl;
#endif
/*
// may be work, but static it returns excess shapes. It is more faster to use OLD version.
// PTV 14.02.2003 NEW version using API of ShapeTool
TopTools_SequenceOfShape aSHUOShapeSeq;
STool->GetAllStyledComponents( SHUO, aSHUOShapeSeq );
for (Standard_Integer si= 1; si <= aSHUOShapeSeq.Length(); si++) {
TopoDS_Shape aSHUOSh = aSHUOShapeSeq.Value(si);
if (!aSHUOSh.IsNull())
settings.Bind ( aSHUOSh, SHUOstyle );
}
*/
// OLD version that was written before ShapeTool API, and ti FASTER for presentation
// get TOP location of SHUO component
TopLoc_Location compLoc = XCAFDoc_ShapeTool::GetLocation ( lab );
TopLoc_IndexedMapOfLocation aPrevLocMap;
// get previous setted location
if ( !loc.IsIdentity() )
aPrevLocMap.Add( loc );
aPrevLocMap.Add( compLoc );
TopTools_SequenceOfShape aSHUOShapeSeq;
// get shapes of SHUO Next_Usage components
getShapesOfSHUO( aPrevLocMap, STool, aSHUOlab, aSHUOShapeSeq );
for (Standard_Integer n = 1; n <= aSHUOShapeSeq.Length(); n++ ) {
TopoDS_Shape aSHUOSh = aSHUOShapeSeq.Value( n );
settings.Bind ( aSHUOSh, SHUOstyle );
}
continue;
}
}
if ( !style.IsSetColorCurv() &&
!style.IsSetColorSurf() &&
style.IsVisible() )
continue;
TopoDS_Shape sub = XCAFDoc_ShapeTool::GetShape ( lab );
sub.Move ( loc );
settings.Bind ( sub, style );
}
}
//=======================================================================
//function : DispatchStyles
//purpose : fill items map (style - shape)
//=======================================================================
// merge style with father (to reflect inheritance)
static Standard_Boolean MergeStyles (XCAFPrs_Style &style, const XCAFPrs_Style &father)
{
if ( ! style.IsSetColorCurv() && father.IsSetColorCurv() )
style.SetColorCurv ( father.GetColorCurv() );
if ( ! style.IsSetColorSurf() && father.IsSetColorSurf() )
style.SetColorSurf ( father.GetColorSurf() );
return style == father;
}
Standard_Boolean XCAFPrs::DispatchStyles (const TopoDS_Shape &shape,
const XCAFPrs_DataMapOfShapeStyle &settings,
XCAFPrs_DataMapOfStyleShape &items,
const XCAFPrs_Style &DefStyle,
const Standard_Boolean force,
const TopAbs_ShapeEnum context)
{
const XCAFPrs_Style *style = &DefStyle;
XCAFPrs_Style ownstyle;
// check own setting of current shape
Standard_Boolean overriden = Standard_False;
if ( settings.IsBound ( shape ) ) {
ownstyle = settings.Find ( shape );
if ( ! MergeStyles ( ownstyle, DefStyle ) ) {
overriden = Standard_True;
style = &ownstyle;
}
}
// iterate on subshapes
BRep_Builder B;
TopoDS_Shape copy = shape.EmptyCopied();
Standard_Boolean suboverride = Standard_False;
Standard_Integer nbDef = 0;
for ( TopoDS_Iterator it(shape); it.More(); it.Next() ) {
if ( DispatchStyles ( it.Value(), settings, items, *style, Standard_False, shape.ShapeType() ) ) {
suboverride = Standard_True;
}
else {
B.Add ( copy, it.Value() );
nbDef++;
}
}
if ( shape.ShapeType() == TopAbs_FACE || ! suboverride )
copy = shape;
else if ( ! nbDef ) return overriden || suboverride; // avoid empty compounds
// if any of styles is overriden regarding to default one, add rest to map
if ( overriden || force ||
( suboverride && context != TopAbs_FACE ) ) { // avoid drawing edges of the same color as face
TopoDS_Compound C;
if ( items.IsBound ( *style ) )
C = TopoDS::Compound ( items.Find ( *style ) );
else {
B.MakeCompound ( C );
items.Bind ( *style, C );
}
B.Add ( C, copy );
}
return overriden || suboverride;
}
//=======================================================================
//function : SetViewNameMode
//purpose :
//=======================================================================
void XCAFPrs::SetViewNameMode(const Standard_Boolean aNameMode )
{
viewnameMode = aNameMode;
}
//=======================================================================
//function : GetViewNameMode
//purpose :
//=======================================================================
Standard_Boolean XCAFPrs::GetViewNameMode()
{
return viewnameMode;
}

View File

@@ -0,0 +1,42 @@
-- File: XCAFPrs_AISObject.cdl
-- Created: Fri Aug 11 16:37:11 2000
-- Author: Andrey BETENEV
-- <abv@doomox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2000
class AISObject from XCAFPrs inherits Shape from AIS
---Purpose: Implements AIS_InteractiveObject functionality
-- for shape in DECAF document
uses
Shape from TopoDS,
PresentationManager3d from PrsMgr,
Presentation from Prs3d,
Label from TDF,
Style from XCAFPrs
is
Create (lab: Label from TDF);
---Purpose: Creates an object to visualise the shape label
AddStyledItem (me: mutable; style: Style from XCAFPrs;
shape: Shape from TopoDS;
aPresentationManager : PresentationManager3d from PrsMgr;
aPresentation : mutable Presentation from Prs3d;
aMode : Integer from Standard = 0)
is private;
Compute (me : mutable;
aPresentationManager : PresentationManager3d from PrsMgr;
aPresentation : mutable Presentation from Prs3d;
aMode : Integer from Standard = 0)
is redefined virtual private;
---Purpose: Redefined method to compute presentation
fields
myLabel : Label from TDF;
end AISObject;

435
src/XCAFPrs/XCAFPrs_AISObject.cxx Executable file
View File

@@ -0,0 +1,435 @@
// File: XCAFPrs_AISObject.cxx
// Created: Fri Aug 11 16:49:09 2000
// Author: Andrey BETENEV
// <abv@doomox.nnov.matra-dtv.fr>
#include <XCAFPrs_AISObject.ixx>
#include <TCollection_ExtendedString.hxx>
#include <gp_Pnt.hxx>
#include <Prs3d_Text.hxx>
#include <Prs3d_LengthAspect.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <Precision.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Iterator.hxx>
#include <BRepTools.hxx>
#include <StdPrs_WFDeflectionShape.hxx>
#include <StdPrs_ShadedShape.hxx>
#include <StdPrs_WFShape.hxx>
#include <AIS_Drawer.hxx>
#include <Graphic3d_Array1OfVertex.hxx>
#include <Graphic3d_Group.hxx>
#include <Quantity_Color.hxx>
#include <Aspect_TypeOfLine.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS_Compound.hxx>
#include <XCAFPrs_Style.hxx>
#include <TopoDS_Shape.hxx>
#include <XCAFPrs_DataMapOfShapeStyle.hxx>
#include <TDF_LabelSequence.hxx>
#include <XCAFPrs_DataMapOfStyleShape.hxx>
#include <TopoDS.hxx>
#include <XCAFPrs_DataMapIteratorOfDataMapOfStyleShape.hxx>
#include <Graphic3d_AspectFillArea3d.hxx>
#include <Aspect_InteriorStyle.hxx>
#include <Aspect_TypeOfLine.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <XCAFPrs.hxx>
#include <TDataStd_Name.hxx>
#include <BRepBndLib.hxx>
#include <TPrsStd_AISPresentation.hxx>
#ifdef DEBUG
#include <DBRep.hxx>
#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 : Compute
//purpose :
//=======================================================================
void DisplayBox(const Handle(Prs3d_Presentation)& aPrs,
const Bnd_Box& B,
const Handle(Prs3d_Drawer)& aDrawer)
{
Standard_Real X[2],Y[2],Z[2];
Standard_Integer Indx [16] ;
if ( B.IsVoid() )
return;
#ifdef BUC60577
Indx [0]=1;Indx [1]=2;Indx [2]=4;Indx [3]=3;
Indx [4]=5;Indx [5]=6;Indx [6]=8;Indx [7]=7;
Indx [8]=1;Indx [9]=3;Indx [10]=7;Indx [11]=5;
Indx [12]=2;Indx [13]=4;Indx [14]=8;Indx [15]=6;
B.Get(X[0], Y[0], Z[0], X[1], Y[1], Z[1]);
#else
Indx [0]=1;Indx [1]=2;Indx [2]=3;Indx [3]=4;Indx [4]=5;Indx [5]=6;Indx [6]=7;
Indx [7]=8;Indx [8]=1;Indx [9]=2;Indx [10]=6;Indx [10]=5;Indx [10]=3;
Indx [10]=4;Indx [10]=8;Indx [10]=7;
B.Get(X[1], Y[1], Z[1], X[2], Y[2], Z[2]);
#endif
Graphic3d_Array1OfVertex V(1,8);
Standard_Integer Rank(0);
for(Standard_Integer k=0;k<=1;k++)
for(Standard_Integer j=0;j<=1;j++)
for(Standard_Integer i=0;i<=1;i++)
V(++Rank) = Graphic3d_Vertex(X[i],Y[j],Z[k]);
Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(aPrs);
Quantity_Color Q;
Aspect_TypeOfLine A;
Standard_Real W;
aDrawer->LineAspect()->Aspect()->Values(Q,A,W);
G->SetGroupPrimitivesAspect(new Graphic3d_AspectLine3d(Q,Aspect_TOL_DOTDASH,W));
G->BeginPrimitives();Standard_Integer I,J;
Graphic3d_Array1OfVertex VVV (1,5);
for(I=1;I<=4;I++){
for(J=1;J<=4;J++){
VVV.SetValue(J,V(Indx[J+4*I-5]));
}
VVV.SetValue(5,VVV(1));
G->Polyline(VVV);
}
G->EndPrimitives();
}
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"<<endl;
cout << "newangl : " << newangle << " # de " << "prevangl : " << prevangle << " OU "<<endl;
cout << "newcoeff : " << newcoeff << " # de " << "prevcoeff : " << prevcoeff << endl;
#endif
BRepTools::Clean(shape);
}
//shading seulement a partir de face...
try {
OCC_CATCH_SIGNALS
if ((Standard_Integer) shape.ShapeType()>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() );
Graphic3d_NameOfMaterial material = ( prs.IsNull() ? Graphic3d_NOM_PLASTIC : prs->Material() );
// Graphic3d_NameOfMaterial material = Material();
SetMaterial ( material );
// 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() ? "" : " <invisible>" ) << endl;
#ifdef DEBUG
char str[200];
sprintf ( str, "si_%d", i );
DBRep::Set ( str, it.Value() );
try { OCC_CATCH_SIGNALS ; } // to handle all till the end of for
catch (Standard_Failure) {
cout << "Exception in AddStyledItem!" << endl;
continue;
}
#endif
i++;
#endif
if (! s.IsVisible() ) continue;
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...
}

28
src/XCAFPrs/XCAFPrs_Driver.cdl Executable file
View File

@@ -0,0 +1,28 @@
-- File: XCAFPrs_Driver.cdl
-- Created: Fri Aug 11 16:30:58 2000
-- Author: data exchange team
-- <det@doomox>
---Copyright: Matra Datavision 2000
class Driver from XCAFPrs inherits Driver from TPrsStd
---Purpose: Implements a driver for presentation of shapes in DECAF
-- document. Its the only purpose is to initialize and return
-- XCAFPrs_AISObject object on request
uses
Label from TDF,
InteractiveObject from AIS
is
Update (me : mutable ; L : Label from TDF;
ais : in out InteractiveObject from AIS)
returns Boolean from Standard is redefined;
GetID (myclass) returns GUID;
---Purpose: returns GUID of the driver
---C++: return const &
end Driver;

44
src/XCAFPrs/XCAFPrs_Driver.cxx Executable file
View File

@@ -0,0 +1,44 @@
// File: XCAFPrs_Driver.cxx
// Created: Fri Aug 11 16:34:45 2000
// Author: data exchange team
// <det@doomox>
#include <XCAFPrs_Driver.ixx>
#include <XCAFPrs_AISObject.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <TDF_Label.hxx>
#include <TDocStd_Document.hxx>
//=======================================================================
//function : Update
//purpose :
//=======================================================================
Standard_Boolean XCAFPrs_Driver::Update (const TDF_Label& L,
Handle(AIS_InteractiveObject)& ais)
{
// cout << "XCAFPrs_Driver::Update" << endl;
// WARNING! The label L can be out of any document
// (this is a case for reading from the file)
// Handle(TDocStd_Document) DOC = TDocStd_Document::Get(L);
XCAFDoc_ShapeTool shapes;
if ( ! shapes.IsShape(L) ) return Standard_False;
ais = new XCAFPrs_AISObject (L);
return Standard_True;
}
//=======================================================================
//function : GetID
//purpose :
//=======================================================================
const Standard_GUID& XCAFPrs_Driver::GetID()
{
static Standard_GUID ID("5b896afc-3adf-11d4-b9b7-0060b0ee281b");
return ID;
}

65
src/XCAFPrs/XCAFPrs_Style.cdl Executable file
View File

@@ -0,0 +1,65 @@
-- File: XCAFPrs_Style.cdl
-- Created: Fri Aug 11 19:29:16 2000
-- Author: Andrey BETENEV
-- <abv@doomox.nnov.matra-dtv.fr>
---Copyright: Matra Datavision 2000
class Style from XCAFPrs
---Purpose: Represents a set of styling settings applicable to
-- a (sub)shape
uses
Color from Quantity
is
Create returns Style from XCAFPrs;
IsSetColorSurf (me) returns Boolean;
GetColorSurf (me) returns Color from Quantity;
SetColorSurf (me: in out; col: Color from Quantity);
UnSetColorSurf (me: in out);
---Purpose: Manage surface color setting
IsSetColorCurv (me) returns Boolean;
GetColorCurv (me) returns Color from Quantity;
SetColorCurv (me: in out; col: Color from Quantity);
UnSetColorCurv (me: in out);
---Purpose: Manage curve color setting
SetVisibility(me: in out; visibility: Boolean from Standard);
IsVisible(me) returns Boolean;
---Purpose: Manage visibility
-- Note: Setting visibility to False makes colors undefined
-- This is necessary for HashCode
IsEqual (me; other: Style from XCAFPrs) returns Boolean;
---Purpose: Returs True if styles are the same
---C++: alias operator ==
---Purpose: Methods for using Style as key in maps
HashCode(myclass; S : Style from XCAFPrs; Upper : Integer) returns Integer;
---Purpose: Returns a HasCode value for the Key <K> in the
-- range 0..Upper.
IsEqual(myclass; S1, S2 : Style from XCAFPrs) returns Boolean;
---Purpose: Returns True when the two keys are the same. Two
-- same keys must have the same hashcode, the
-- contrary is not necessary.
fields
-- defColor: Boolean;
defColorSurf: Boolean;
defColorCurv: Boolean;
myVisibility: Boolean from Standard;
-- myColor: Color from Quantity;
myColorSurf: Color from Quantity;
myColorCurv: Color from Quantity;
end Style;

164
src/XCAFPrs/XCAFPrs_Style.cxx Executable file
View File

@@ -0,0 +1,164 @@
// File: XCAFPrs_Style.cxx
// Created: Fri Aug 11 19:36:48 2000
// Author: Andrey BETENEV
// <abv@doomox.nnov.matra-dtv.fr>
#include <XCAFPrs_Style.ixx>
//=======================================================================
//function : XCAFPrs_Style
//purpose :
//=======================================================================
XCAFPrs_Style::XCAFPrs_Style () :
defColorSurf(Standard_False),
defColorCurv(Standard_False),
myVisibility(Standard_True)
{
}
//=======================================================================
//function : IsSetColorSurf
//purpose :
//=======================================================================
Standard_Boolean XCAFPrs_Style::IsSetColorSurf () const
{
return defColorSurf;
}
//=======================================================================
//function : GetColorSurf
//purpose :
//=======================================================================
Quantity_Color XCAFPrs_Style::GetColorSurf () const
{
return myColorSurf;
}
//=======================================================================
//function : SetColorSurf
//purpose :
//=======================================================================
void XCAFPrs_Style::SetColorSurf (const Quantity_Color &col)
{
myColorSurf = col;
defColorSurf = Standard_True;
}
//=======================================================================
//function : UnSetColorSurf
//purpose :
//=======================================================================
void XCAFPrs_Style::UnSetColorSurf ()
{
defColorSurf = Standard_False;
myColorSurf.SetValues ( Quantity_NOC_YELLOW );
}
//=======================================================================
//function : IsSetColorCurv
//purpose :
//=======================================================================
Standard_Boolean XCAFPrs_Style::IsSetColorCurv () const
{
return defColorCurv;
}
//=======================================================================
//function : GetColorCurv
//purpose :
//=======================================================================
Quantity_Color XCAFPrs_Style::GetColorCurv () const
{
return myColorCurv;
}
//=======================================================================
//function : SetColorCurv
//purpose :
//=======================================================================
void XCAFPrs_Style::SetColorCurv (const Quantity_Color &col)
{
myColorCurv = col;
defColorCurv = Standard_True;
}
//=======================================================================
//function : UnSetColorCurv
//purpose :
//=======================================================================
void XCAFPrs_Style::UnSetColorCurv ()
{
defColorCurv = Standard_False;
myColorCurv.SetValues ( Quantity_NOC_YELLOW );
}
//=======================================================================
//function : SetVisibility
//purpose :
//=======================================================================
void XCAFPrs_Style::SetVisibility (const Standard_Boolean visibility)
{
myVisibility = visibility;
if ( ! visibility ) { UnSetColorSurf(); UnSetColorCurv(); } // for hash codes
}
//=======================================================================
//function : IsVisible
//purpose :
//=======================================================================
Standard_Boolean XCAFPrs_Style::IsVisible () const
{
return myVisibility;
}
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
Standard_Boolean XCAFPrs_Style::IsEqual (const XCAFPrs_Style &other) const
{
return myVisibility == other.myVisibility &&
( ! myVisibility ||
( defColorSurf == other.defColorSurf &&
defColorCurv == other.defColorCurv &&
( ! defColorSurf || myColorSurf == other.myColorSurf ) &&
( ! defColorCurv || myColorCurv == other.myColorCurv ) ) );
}
//=======================================================================
//function : HashCode
//purpose :
//=======================================================================
Standard_Integer XCAFPrs_Style::HashCode (const XCAFPrs_Style& S, const Standard_Integer Upper)
{
int *meintPtr = (int*)&S;
Standard_Integer aHashCode=0, i, aSize = sizeof(S) / sizeof(int);
for (i = 0; i < aSize; i++, meintPtr++) {
aHashCode = aHashCode ^ *meintPtr;
}
return ::HashCode( aHashCode, Upper);
}
//=======================================================================
//function : IsEqual
//purpose :
//=======================================================================
Standard_Boolean XCAFPrs_Style::IsEqual (const XCAFPrs_Style& S1, const XCAFPrs_Style& S2)
{
return S1.IsEqual(S2);
}