1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-03 14:10:33 +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

172
src/DNaming/DNaming.cdl Executable file
View File

@@ -0,0 +1,172 @@
-- File: DNaming.cdl
-- Created: Wed Jan 8 15:54:45 1997
-- Author: VAUTHIER Jean-Claude
---Copyright: Matra Datavision 1997
package DNaming
---Purpose:
uses
Draw,
TCollection,
TColStd,
TopAbs,
gp,
TDF,
TDataStd,
TFunction,
TNaming,
TopoDS,
TopTools,
BRepPrimAPI,
BRepFilletAPI,
BRepBuilderAPI,
BRepAlgoAPI
is
class BoxDriver;
class CylinderDriver;
class SphereDriver;
class SelectionDriver;
class BooleanOperationDriver;
class FilletDriver;
class TransformationDriver;
class PrismDriver;
class RevolutionDriver;
class PointDriver;
class Line3DDriver;
class DataMapOfShapeOfName instantiates
DataMap from TCollection(Shape from TopoDS,
AsciiString from TCollection,
ShapeMapHasher from TopTools);
GetReal (theFunction : Function from TFunction; thePosition : Integer from Standard)
returns Real from TDataStd;
GetInteger (theFunction : Function from TFunction;thePosition : Integer from Standard)
returns Integer from TDataStd;
GetString (theFunction : Function from TFunction; thePosition : Integer from Standard)
returns Name from TDataStd;
ComputeAxis (theNS : NamedShape from TNaming; theAx1 : in out Ax1 from gp)
returns Boolean from Standard;
-- manipulation by function - object
GetFunctionResult(theFunction : Function from TFunction)
returns NamedShape from TNaming;
GetObjectArg(theFunction : Function from TFunction; thePosition : Integer from Standard)
returns UAttribute from TDataStd;
SetObjectArg(theFunction : Function from TFunction; thePosition : Integer from Standard;
theNewValue : UAttribute from TDataStd);
GetObjectValue(theObject : UAttribute from TDataStd)
returns NamedShape from TNaming;
GetLastFunction(theObject : UAttribute from TDataStd)
returns Function from TFunction;
GetFirstFunction(theObject : UAttribute from TDataStd)
returns Function from TFunction;
GetPrevFunction(theFunction : Function from TFunction)
returns Function from TFunction;
GetObjectFromFunction(theFunction : Function from TFunction)
returns UAttribute from TDataStd;
IsAttachment(theObject : UAttribute from TDataStd)
returns Boolean from Standard;
GetAttachmentsContext (theObject : UAttribute from TDataStd)
returns NamedShape from TNaming;
ComputeSweepDir ( theShape : Shape from TopoDS; theAxis : in out Ax1 from gp)
returns Boolean from Standard;
-- Naming short-cuts
LoadAndOrientModifiedShapes(
MakeShape : in out MakeShape from BRepBuilderAPI;
ShapeIn : in Shape from TopoDS;
GeneratedFrom : in ShapeEnum from TopAbs;
Buider : in out Builder from TNaming;
SubShapesOfResult : in DataMapOfShapeShape from TopTools);
LoadAndOrientGeneratedShapes(
MakeShape : in out MakeShape from BRepBuilderAPI;
ShapeIn : in Shape from TopoDS;
GeneratedFrom : in ShapeEnum from TopAbs;
Buider : in out Builder from TNaming;
SubShapesOfResult : in DataMapOfShapeShape from TopTools);
LoadDeletedShapes(
MakeShape : in out MakeShape from BRepBuilderAPI;
ShapeIn : in Shape from TopoDS;
KindOfDeletedShape : in ShapeEnum from TopAbs;
Buider : in out Builder from TNaming);
LoadResult(theLabel : Label from TDF; MS : in out BooleanOperation from BRepAlgoAPI);
-- old methods
CurrentShape (ShapeEntry : CString from Standard;
Data : Data from TDF)
returns Shape from TopoDS;
GetShape (ShapeEntry : CString from Standard;
Data : Data from TDF;
Shapes : in out ListOfShape from TopTools);
GetEntry (Shape : in Shape from TopoDS;
Data : in Data from TDF;
Status : in out Integer from Standard)
---Purpose: Status = 0 Not found,
-- Status = 1 One shape,
-- Status = 2 More than one shape.
returns AsciiString from TCollection;
LoadImportedShape(theResultLabel : Label from TDF;
theShape : Shape from TopoDS);
---Purpose: Loads the Shape to DF
LoadPrime(theResultLabel : Label from TDF;
theShape : Shape from TopoDS);
---Purpose: Reloads sub-shapes of the Shape to DF
AllCommands (DI : in out Interpretor from Draw);
BasicCommands (DI : in out Interpretor from Draw);
---Purpose: commands relatives to NamedShape
ToolsCommands (DI : in out Interpretor from Draw);
SelectionCommands (DI : in out Interpretor from Draw);
---Purpose: commands relatives to Naming
ModelingCommands (DI : in out Interpretor from Draw);
---Purpose: commands for testing Naming
end DNaming;

907
src/DNaming/DNaming.cxx Executable file
View File

@@ -0,0 +1,907 @@
// File: DNaming.cxx
// Created: Thu Jan 9 17:15:19 1997
// Author: VAUTHIER Jean-Claude & Fricaud Yves
#include <DNaming.ixx>
#include <DDF.hxx>
#include <DDF_Data.hxx>
#include <Draw.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_LabelList.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_Tool.hxx>
#include <TDF_TagSource.hxx>
#include <TNaming_Iterator.hxx>
#include <TNaming_Tool.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Builder.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <TopTools_DataMapOfShapeListOfShape.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <BRepTools.hxx>
#include <TDF_Reference.hxx>
#include <TDataStd_TreeNode.hxx>
#include <BRepAlgoAPI_BooleanOperation.hxx>
#include <gp_Vec.hxx>
#include <gp_Ax1.hxx>
#include <gp_Pln.hxx>
#include <TopoDS_Edge.hxx>
#include <Geom_Curve.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Line.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <BRepLib_FindSurface.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <ModelDefinitions.hxx>
//=======================================================================
//function : DNaming_DFandUS
//purpose :
//=======================================================================
// Standard_Boolean DNaming_DFandUS(char* a,
// Handle(TDF_Data)& ND,
// Handle(TNaming_UsedShapes)& US)
// {
// Handle(DDF_Data) DND = Handle(DDF_Data)::DownCast (Draw::Get(a));
// if (DND.IsNull ()) return 0;
// ND = DND->DataFramework ();
// ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
// return 1;
// }
//=======================================================================
//function : GetShape
//purpose :
//=======================================================================
void DNaming::GetShape (const Standard_CString LabelName,
const Handle(TDF_Data)& DF,
TopTools_ListOfShape& L)
{
L.Clear();
TDF_Label Label;
Standard_Boolean Found = DDF::AddLabel (DF, LabelName, Label);
if (Found) {
TNaming_Iterator it (Label, DF->Transaction ());
for (; it.More(); it.Next()) {
L.Append(it.NewShape());
}
}
}
//=======================================================================
//function : BuildMap
//purpose :
//=======================================================================
void DNaming_BuildMap(TDF_LabelMap& Updated,
const TDF_Label& Lab)
{
TDF_ChildIterator it(Lab);
for (; it.More(); it.Next()) {
Updated.Add(it.Value());
DNaming_BuildMap(Updated,it.Value());
}
}
//=======================================================================
//function : CurrentShape
//purpose :
//=======================================================================
TopoDS_Shape DNaming::CurrentShape (const Standard_CString LabelName,
const Handle(TDF_Data)& DF)
{
TopoDS_Shape S;
TDF_Label Label;
Standard_Boolean Found = DDF::AddLabel (DF, LabelName, Label);
if (!Found) {
cout <<"no labels"<<endl;
return S;
}
if (Found) {
Handle(TNaming_NamedShape) NS;
Label.FindAttribute(TNaming_NamedShape::GetID(),NS);
S = TNaming_Tool::CurrentShape(NS);
if (S.IsNull())
cout <<"current shape from "<< LabelName <<" is deleted"<<endl;
return S;
}
return S;
}
//=======================================================================
//function : GetEntry
//purpose :
//=======================================================================
TCollection_AsciiString DNaming::GetEntry (const TopoDS_Shape& Shape,
const Handle(TDF_Data)& DF,
Standard_Integer& Status)
{
Status = 0;
//Handle(TNaming_UsedShapes) US;
//DF->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
if (!TNaming_Tool::HasLabel (DF->Root(), Shape)) {
return TCollection_AsciiString ();
}
Standard_Integer Transdef;
TDF_Label Lab = TNaming_Tool::Label (DF->Root(), Shape,Transdef);
TCollection_AsciiString entry; TDF_Tool::Entry(Lab,entry);
//Update Status;
TNaming_Iterator it(Lab,DF->Transaction());
for (; it.More(); it.Next()) {
Status++;
if (Status == 2) break;
}
return entry;
}
//=======================================================================
//function : AllCommands
//purpose :
//=======================================================================
void DNaming::AllCommands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
done = Standard_True;
DNaming::BasicCommands (theCommands);
DNaming::ToolsCommands (theCommands);
DNaming::SelectionCommands (theCommands);
DNaming::ModelingCommands (theCommands);
// define the TCL variable Draw_NamingData
const char* com = "set Draw_NamingData 1";
theCommands.Eval(com);
}
//=======================================================================
//=======================================================================
//function : LoadC0Vertices
//purpose : Method for internal use. It is used by Load() method.
//=======================================================================
static void LoadC0Vertices(const TopoDS_Shape& S,
const Handle(TDF_TagSource)& Tagger)
{
TopTools_DataMapOfShapeListOfShape vertexNaborFaces;
TopTools_ListOfShape empty;
TopExp_Explorer explF(S, TopAbs_FACE);
for (; explF.More(); explF.Next()) {
const TopoDS_Shape& aFace = explF.Current();
TopExp_Explorer explV(aFace, TopAbs_VERTEX);
for (; explV.More(); explV.Next()) {
const TopoDS_Shape& aVertex = explV.Current();
if (!vertexNaborFaces.IsBound(aVertex)) vertexNaborFaces.Bind(aVertex, empty);
Standard_Boolean faceIsNew = Standard_True;
TopTools_ListIteratorOfListOfShape itrF(vertexNaborFaces.Find(aVertex));
for (; itrF.More(); itrF.Next()) {
if (itrF.Value().IsSame(aFace)) {
faceIsNew = Standard_False;
break;
}
}
if (faceIsNew) {
vertexNaborFaces.ChangeFind(aVertex).Append(aFace);
}
}
}
TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(vertexNaborFaces);
for (; itr.More(); itr.Next()) {
const TopTools_ListOfShape& naborFaces = itr.Value();
if (naborFaces.Extent() < 3) {
TNaming_Builder bC0Vertex(Tagger->NewChild());
bC0Vertex.Generated(itr.Key());
}
}
}
//=======================================================================
//function : LoadC0Edges
//purpose : Method for internal use. It is used by Load() method.
//=======================================================================
static void LoadC0Edges(const TopoDS_Shape& S,
const Handle(TDF_TagSource)& Tagger)
{
TopTools_DataMapOfShapeListOfShape edgeNaborFaces;
TopTools_ListOfShape empty;
TopExp_Explorer explF(S, TopAbs_FACE);
for (; explF.More(); explF.Next()) {
const TopoDS_Shape& aFace = explF.Current();
TopExp_Explorer explV(aFace, TopAbs_EDGE);
for (; explV.More(); explV.Next()) {
const TopoDS_Shape& anEdge = explV.Current();
if (!edgeNaborFaces.IsBound(anEdge)) edgeNaborFaces.Bind(anEdge, empty);
Standard_Boolean faceIsNew = Standard_True;
TopTools_ListIteratorOfListOfShape itrF(edgeNaborFaces.Find(anEdge));
for (; itrF.More(); itrF.Next()) {
if (itrF.Value().IsSame(aFace)) {
faceIsNew = Standard_False;
break;
}
}
if (faceIsNew) {
edgeNaborFaces.ChangeFind(anEdge).Append(aFace);
}
}
}
TopTools_MapOfShape anEdgesToDelete;
TopExp_Explorer anEx(S,TopAbs_EDGE); // mpv: new explorer iterator becouse we need keep edges order
for(;anEx.More();anEx.Next()) {
Standard_Boolean aC0 = Standard_False;
TopoDS_Shape anEdge1 = anEx.Current();
if (edgeNaborFaces.IsBound(anEdge1)) {
const TopTools_ListOfShape& aList1 = edgeNaborFaces.Find(anEdge1);
if (aList1.Extent()<2) continue; // mpv (06.09.2002): these edges already was loaded
TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itr(edgeNaborFaces);
for (; itr.More(); itr.Next()) {
TopoDS_Shape anEdge2 = itr.Key();
if(anEdgesToDelete.Contains(anEdge2)) continue;
if (anEdge1.IsSame(anEdge2)) continue;
const TopTools_ListOfShape& aList2 = itr.Value();
// compare lists of the neighbour faces of edge1 and edge2
if (aList1.Extent() == aList2.Extent()) {
Standard_Integer aMatches = 0;
for(TopTools_ListIteratorOfListOfShape aLIter1(aList1);aLIter1.More();aLIter1.Next())
for(TopTools_ListIteratorOfListOfShape aLIter2(aList2);aLIter2.More();aLIter2.Next())
if (aLIter1.Value().IsSame(aLIter2.Value())) aMatches++;
if (aMatches == aList1.Extent()) {
aC0=Standard_True;
TNaming_Builder bC0Edge(Tagger->NewChild());
bC0Edge.Generated(anEdge2);
//edgeNaborFaces.UnBind(anEdge2);
anEdgesToDelete.Add(anEdge2);
}
}
}
//VUN (10/2/2005) avoid UnBind during iterating -^
TopTools_MapIteratorOfMapOfShape itDelete(anEdgesToDelete);
for(;itDelete.More();itDelete.Next()) {
edgeNaborFaces.UnBind(itDelete.Key());
}
edgeNaborFaces.UnBind(anEdge1);
}
if (aC0) {
TNaming_Builder bC0Edge(Tagger->NewChild());
bC0Edge.Generated(anEdge1);
}
}
}
//
//=======================================================================
//function : GetDangleShapes
//purpose : Returns dangle sub shapes Generator - Dangle.
//=======================================================================
static Standard_Boolean GetDangleShapes(const TopoDS_Shape& ShapeIn,
const TopAbs_ShapeEnum GeneratedFrom,
TopTools_DataMapOfShapeShape& Dangles)
{
Dangles.Clear();
TopTools_IndexedDataMapOfShapeListOfShape subShapeAndAncestors;
TopAbs_ShapeEnum GeneratedTo;
if (GeneratedFrom == TopAbs_FACE) GeneratedTo = TopAbs_EDGE;
else if (GeneratedFrom == TopAbs_EDGE) GeneratedTo = TopAbs_VERTEX;
else return Standard_False;
TopExp::MapShapesAndAncestors(ShapeIn, GeneratedTo, GeneratedFrom, subShapeAndAncestors);
for (Standard_Integer i = 1; i <= subShapeAndAncestors.Extent(); i++) {
const TopoDS_Shape& mayBeDangle = subShapeAndAncestors.FindKey(i);
const TopTools_ListOfShape& ancestors = subShapeAndAncestors.FindFromIndex(i);
if (ancestors.Extent() == 1) Dangles.Bind(ancestors.First(), mayBeDangle);
}
return Dangles.Extent();
}
//=======================================================================
//function : LoadGeneratedDangleShapes
//purpose :
//=======================================================================
static void LoadGeneratedDangleShapes(const TopoDS_Shape& ShapeIn,
const TopAbs_ShapeEnum GeneratedFrom,
TNaming_Builder& Builder)
{
TopTools_DataMapOfShapeShape dangles;
if (!GetDangleShapes(ShapeIn, GeneratedFrom, dangles)) return;
TopTools_DataMapIteratorOfDataMapOfShapeShape itr(dangles);
for (; itr.More(); itr.Next()) Builder.Generated(itr.Key(), itr.Value());
}
//=======================================================================
//function : LoadNextLevels
//purpose : Method for internal use. Is used by LoadFirstLevel()
//=======================================================================
static void LoadNextLevels(const TopoDS_Shape& S,
const Handle(TDF_TagSource)& Tagger)
{
if (S.ShapeType() == TopAbs_SOLID) {
TopExp_Explorer expl(S, TopAbs_FACE);
for (; expl.More(); expl.Next()) {
TNaming_Builder bFace(Tagger->NewChild());
bFace.Generated(expl.Current());
}
} else if (S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_FACE) {
// load faces and all the free edges
TopTools_IndexedMapOfShape Faces;
TopExp::MapShapes(S, TopAbs_FACE, Faces);
if (Faces.Extent() > 1 || (S.ShapeType() == TopAbs_SHELL && Faces.Extent() == 1)) {
TopExp_Explorer expl(S, TopAbs_FACE);
for (; expl.More(); expl.Next()) {
TNaming_Builder bFace(Tagger->NewChild());
bFace.Generated(expl.Current());
}
}
TopTools_IndexedDataMapOfShapeListOfShape anEdgeAndNeighbourFaces;
TopExp::MapShapesAndAncestors(S, TopAbs_EDGE, TopAbs_FACE, anEdgeAndNeighbourFaces);
for (Standard_Integer i = 1; i <= anEdgeAndNeighbourFaces.Extent(); i++) {
const TopTools_ListOfShape& aLL = anEdgeAndNeighbourFaces.FindFromIndex(i);
if (aLL.Extent() < 2) {
TNaming_Builder bFreeEdges(Tagger->NewChild());
bFreeEdges.Generated(anEdgeAndNeighbourFaces.FindKey(i));
} else {
TopTools_ListIteratorOfListOfShape anIter(aLL);
const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
anIter.Next();
if(aFace.IsEqual(anIter.Value())) {
TNaming_Builder bFreeEdges(Tagger->NewChild());
bFreeEdges.Generated(anEdgeAndNeighbourFaces.FindKey(i));
}
}
}
} else if (S.ShapeType() == TopAbs_WIRE) {
TopTools_IndexedMapOfShape Edges;
BRepTools::Map3DEdges(S, Edges);
if (Edges.Extent() == 1) {
TNaming_Builder bEdge(Tagger->NewChild());
bEdge.Generated(Edges.FindKey(1));
TopExp_Explorer expl(S, TopAbs_VERTEX);
for (; expl.More(); expl.Next()) {
TNaming_Builder bVertex(Tagger->NewChild());
bVertex.Generated(expl.Current());
}
} else {
TopExp_Explorer expl(S, TopAbs_EDGE);
for (; expl.More(); expl.Next()) {
TNaming_Builder bEdge(Tagger->NewChild());
bEdge.Generated(expl.Current());
}
// and load generated vertices.
TopTools_DataMapOfShapeShape generated;
if (GetDangleShapes(S, TopAbs_EDGE, generated)) {
TNaming_Builder bGenVertices(Tagger->NewChild());
LoadGeneratedDangleShapes(S, TopAbs_EDGE, bGenVertices);
}
}
} else if (S.ShapeType() == TopAbs_EDGE) {
TopExp_Explorer expl(S, TopAbs_VERTEX);
for (; expl.More(); expl.Next()) {
TNaming_Builder bVertex(Tagger->NewChild());
bVertex.Generated(expl.Current());
}
}
}
//=======================================================================
//function : LoadFirstLevel
//purpose : Method for internal use. Is used by Load()
//=======================================================================
static void LoadFirstLevel(const TopoDS_Shape& S,
const Handle(TDF_TagSource)& Tagger)
{
if (S.ShapeType() == TopAbs_COMPOUND || S.ShapeType() == TopAbs_COMPSOLID) {
TopoDS_Iterator itr(S);
for (; itr.More(); itr.Next()) {
TNaming_Builder bIndependantShapes(Tagger->NewChild());
bIndependantShapes.Generated(itr.Value());
if (itr.Value().ShapeType() == TopAbs_COMPOUND || itr.Value().ShapeType() == TopAbs_COMPSOLID) {
LoadFirstLevel(itr.Value(), Tagger);
} else LoadNextLevels(itr.Value(), Tagger);
}
} else LoadNextLevels(S, Tagger);
}
//=======================================================================
//function : Load
//purpose : To load an ImportShape
// Use this method for a topological naming of an imported shape
//=======================================================================
void DNaming::LoadImportedShape(const TDF_Label& theResultLabel,
const TopoDS_Shape& theShape) {
theResultLabel.ForgetAllAttributes();
TNaming_Builder aBuilder(theResultLabel);
aBuilder.Generated(theShape);
Handle(TDF_TagSource) aTagger = TDF_TagSource::Set(theResultLabel);
if (aTagger.IsNull()) return;
aTagger->Set(0);
LoadFirstLevel(theShape, aTagger);
LoadC0Edges(theShape, aTagger);
LoadC0Vertices(theShape, aTagger);
}
//=======================================================================
//function : LoadPrime
//purpose :
//=======================================================================
void DNaming::LoadPrime(const TDF_Label& theResultLabel,
const TopoDS_Shape& theShape) {
Handle(TDF_TagSource) aTagger = TDF_TagSource::Set(theResultLabel);
if (aTagger.IsNull()) return;
aTagger->Set(0);
LoadFirstLevel(theShape, aTagger);
LoadC0Edges(theShape, aTagger);
LoadC0Vertices(theShape, aTagger);
}
//
//=======================================================================
//function : Real
//purpose : Gives the access to a real argument
//=======================================================================
Handle(TDataStd_Real) DNaming::GetReal(const Handle(TFunction_Function)& theFunction,
const Standard_Integer thePosition) {
Handle(TDataStd_Real) aReal;
if (!POSITION(theFunction, thePosition).FindAttribute(TDataStd_Real::GetID(),aReal))
aReal = TDataStd_Real::Set(POSITION(theFunction,thePosition),0.0);
return aReal;
}
//=======================================================================
//function : Integer
//purpose : Give an access to integer attribute
//=======================================================================
Handle(TDataStd_Integer) DNaming::GetInteger(const Handle(TFunction_Function)& theFunction,
const Standard_Integer thePosition) {
Handle(TDataStd_Integer) anInteger;
if (!POSITION(theFunction,thePosition).FindAttribute(TDataStd_Integer::GetID(),anInteger))
anInteger = TDataStd_Integer::Set(POSITION(theFunction,thePosition),0);
return anInteger;
}
//=======================================================================
//function : String
//purpose : Returns Name attribute
//=======================================================================
Handle(TDataStd_Name) DNaming::GetString(const Handle(TFunction_Function)& theFunction,
const Standard_Integer thePosition) {
Handle(TDataStd_Name) aString;
if (!POSITION(theFunction,thePosition).FindAttribute(TDataStd_Name::GetID(),aString))
aString = TDataStd_Name::Set(POSITION(theFunction,thePosition),"");
return aString;
}
//=======================================================================
//function : GetResult
//purpose : Returns a result of a function, which is stored on a second label
//=======================================================================
Handle(TNaming_NamedShape) DNaming::GetFunctionResult(const Handle(TFunction_Function)& theFunction)
{
Handle(TNaming_NamedShape) aNShape;
theFunction->Label().FindChild(FUNCTION_RESULT_LABEL).FindAttribute(TNaming_NamedShape::GetID(),aNShape);
return aNShape;
}
//=======================================================================
//function : Object
//purpose : Returns UAttribute associated with Object
//=======================================================================
Handle(TDataStd_UAttribute) DNaming::GetObjectArg(const Handle(TFunction_Function)& theFunction,
const Standard_Integer thePosition) {
Handle(TDataStd_UAttribute) anObject;
Handle(TDF_Reference) aReference;
if (POSITION(theFunction,thePosition).FindAttribute(TDF_Reference::GetID(), aReference))
aReference->Get().FindAttribute(GEOMOBJECT_GUID, anObject);
return anObject;
}
//=======================================================================
//function : SetObject
//purpose : Replace the argument by new value.
//=======================================================================
void DNaming::SetObjectArg (const Handle(TFunction_Function)& theFunction,
const Standard_Integer thePosition,
const Handle(TDataStd_UAttribute)& theNewValue)
{
if(theNewValue.IsNull()) return;
TDF_Reference::Set(POSITION(theFunction, thePosition),theNewValue->Label());
}
//=======================================================================
//function : GetObjectValue
//purpose : Returns NamedShape of the Object
//=======================================================================
Handle(TNaming_NamedShape) DNaming::GetObjectValue(const Handle(TDataStd_UAttribute)& theObject)
{
Handle(TNaming_NamedShape) aNS;
#ifdef DEB
// cout <<"DNaming::GetObjectValue : Obj is NULL = " << theObject.IsNull() <<endl;
// cout << "Object = " << theObject->DynamicType()->Name() <<endl;
// Standard_CString aStrGUID = "00000000-0000-0000-0000-000000000000";
// Standard_GUID aGd = theObject->ID();
// aGd.ShallowDump(cout);
#endif
if(!theObject.IsNull() && theObject->ID() == GEOMOBJECT_GUID) {
Handle(TDF_Reference) aReference;
if(theObject->FindAttribute(TDF_Reference::GetID(), aReference))
aReference->Get().FindAttribute(TNaming_NamedShape::GetID(), aNS);
}
return aNS;
/*
Handle(TFunction_Function) aFun;
Handle(TDataStd_TreeNode) aNode;
objLabel.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
if(aNode.IsNull()) return aFun;
if(!aNode->HasFirst()) return aFun;
else
aNode = aNode->First();
while(!aNode.IsNull()) {
if(aNode->FindAttribute(TFunction_Function::GetID(), aFun)) {
const Standard_GUID& aGUID = aFun->GetDriverGUID();
if(aGUID == funGUID) break;
else aFun.Nullify();
}
aNode = aNode->Next();
}
*/
}
//=======================================================================
//function : GetPrevFunction
//purpose : Returns previus function
//=======================================================================
Handle(TFunction_Function) DNaming::GetPrevFunction(const Handle(TFunction_Function)& theFunction)
{
Handle(TFunction_Function) aPrevFun;
if(!theFunction.IsNull() ) {
Handle(TDataStd_TreeNode) aNode;
theFunction->FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
while(!aNode.IsNull()) {
if(!aNode->HasPrevious()) return aPrevFun;
else
aNode = aNode->Previous();
aNode->FindAttribute(TFunction_Function::GetID(),aPrevFun );
if(!aPrevFun.IsNull())
break;
}
}
return aPrevFun;
/*
while(!aNode.IsNull()) {
if(aNode->FindAttribute(TFunction_Function::GetID(), aFun)) {
const Standard_GUID& aGUID = aFun->GetDriverGUID();
if(aGUID == funGUID) break;
else aFun.Nullify();
}
aNode = aNode->Next();
}
*/
}
//=======================================================================
//function : GetFirstFunction
//purpose : Returns first function
//=======================================================================
Handle(TFunction_Function) DNaming::GetFirstFunction(const Handle(TDataStd_UAttribute)& theObject)
{
Handle(TFunction_Function) aFirstFun;
if(!theObject.IsNull() ) {
Handle(TDataStd_TreeNode) aNode;
theObject->FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
if(aNode.IsNull()) return aFirstFun;
if(!aNode->HasFirst()) return aFirstFun;
else
aNode = aNode->First();
while(!aNode.IsNull()) {
aNode->FindAttribute(TFunction_Function::GetID(), aFirstFun );
if(!aFirstFun.IsNull())
break;
aNode = aNode->Next();
}
}
return aFirstFun;
}
//=======================================================================
//function : GetLastFunction
//purpose : Returns Last function
//=======================================================================
Handle(TFunction_Function) DNaming::GetLastFunction(const Handle(TDataStd_UAttribute)& theObject)
{
Handle(TFunction_Function) aLastFun;
if(!theObject.IsNull() ) {
Handle(TDataStd_TreeNode) aNode;
theObject->FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
if(aNode.IsNull()) return aLastFun;
if(!aNode->HasFirst()) return aLastFun;
else
aNode = aNode->First();
while(!aNode.IsNull()) {
if(aNode->IsAttribute(TFunction_Function::GetID()))
aNode->FindAttribute(TFunction_Function::GetID(), aLastFun);
aNode = aNode->Next();
}
}
return aLastFun;
}
//=======================================================================
//function : GetObjectFromFunction
//purpose : Returns Object
//=======================================================================
Handle(TDataStd_UAttribute) DNaming::GetObjectFromFunction(const Handle(TFunction_Function)& theFunction)
{
Handle(TDataStd_UAttribute) anObject;
if(!theFunction.IsNull() ) {
Handle(TDataStd_TreeNode) aNode;
theFunction->FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), aNode);
if(!aNode.IsNull()) {
if(!aNode->HasFather()) return anObject;
else
aNode = aNode->Father();
aNode->FindAttribute(GEOMOBJECT_GUID, anObject);
}
}
return anObject;
/*
while(!aNode.IsNull()) {
if(aNode->FindAttribute(TFunction_Function::GetID(), aFun)) {
const Standard_GUID& aGUID = aFun->GetDriverGUID();
if(aGUID == funGUID) break;
else aFun.Nullify();
}
aNode = aNode->Next();
}
*/
}
//=======================================================================
//function : LoadResult
//purpose :
//=======================================================================
void DNaming::LoadResult(const TDF_Label& ResultLabel, BRepAlgoAPI_BooleanOperation& MS)
{
Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(ResultLabel);
if (Tagger.IsNull()) return;
Tagger->Set(0);
TNaming_Builder Builder (ResultLabel);
TopoDS_Shape aResult = MS.Shape();
if (aResult.ShapeType() == TopAbs_COMPOUND) {
Standard_Integer nbSubResults = 0;
TopoDS_Iterator itr(aResult);
for (; itr.More(); itr.Next()) nbSubResults++;
if (nbSubResults == 1) {
itr.Initialize(aResult);
if (itr.More()) aResult = itr.Value();
}
}
if (MS.Shape1().IsNull()) Builder.Generated(aResult);
else {
Builder.Modify(MS.Shape1(), aResult);
}
}
//=======================================================================
//function : LoadAndOrientModifiedShapes
//purpose :
//=======================================================================
void DNaming::LoadAndOrientModifiedShapes (BRepBuilderAPI_MakeShape& MS,
const TopoDS_Shape& ShapeIn,
const TopAbs_ShapeEnum KindOfShape,
TNaming_Builder& Builder,
const TopTools_DataMapOfShapeShape& SubShapes)
{
TopTools_MapOfShape View;
TopExp_Explorer ShapeExplorer (ShapeIn, KindOfShape);
TopTools_ListOfShape Shapes;
for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
const TopoDS_Shape& Root = ShapeExplorer.Current ();
if (!View.Add(Root)) continue;
const TopTools_ListOfShape& Shapes = MS.Modified (Root);
TopTools_ListIteratorOfListOfShape ShapesIterator (Shapes);
for (;ShapesIterator.More (); ShapesIterator.Next ()) {
TopoDS_Shape newShape = ShapesIterator.Value ();
if (SubShapes.IsBound(newShape)) {
newShape.Orientation((SubShapes(newShape)).Orientation());
}
if (!Root.IsSame (newShape)) Builder.Modify (Root, newShape );
}
}
}
//=======================================================================
//function : LoadDeletedShapes
//purpose :
//=======================================================================
void DNaming::LoadDeletedShapes (BRepBuilderAPI_MakeShape& MS,
const TopoDS_Shape& ShapeIn,
const TopAbs_ShapeEnum KindOfShape,
TNaming_Builder& Builder)
{
TopTools_MapOfShape View;
TopExp_Explorer ShapeExplorer (ShapeIn, KindOfShape);
for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
const TopoDS_Shape& Root = ShapeExplorer.Current ();
if (!View.Add(Root)) continue;
if (MS.IsDeleted (Root)) {
Builder.Delete (Root);
}
}
}
//=======================================================================
//function : LoadAndOrientGeneratedShapes
//purpose :
//=======================================================================
void DNaming::LoadAndOrientGeneratedShapes (BRepBuilderAPI_MakeShape& MS,
const TopoDS_Shape& ShapeIn,
const TopAbs_ShapeEnum KindOfShape,
TNaming_Builder& Builder,
const TopTools_DataMapOfShapeShape& SubShapes)
{
TopTools_MapOfShape View;
TopExp_Explorer ShapeExplorer (ShapeIn, KindOfShape);
for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
const TopoDS_Shape& Root = ShapeExplorer.Current ();
if (!View.Add(Root)) continue;
const TopTools_ListOfShape& Shapes = MS.Generated (Root);
TopTools_ListIteratorOfListOfShape ShapesIterator (Shapes);
for (;ShapesIterator.More (); ShapesIterator.Next ()) {
TopoDS_Shape newShape = ShapesIterator.Value ();
if (SubShapes.IsBound(newShape)) {
newShape.Orientation((SubShapes(newShape)).Orientation());
}
if (!Root.IsSame (newShape)) Builder.Generated (Root,newShape );
}
}
}
//=======================================================================
//function : ComputeNormalizedVector
//purpose : Computes normalized vector from shape if it is possible
//=======================================================================
Standard_Boolean DNaming::ComputeAxis (const Handle(TNaming_NamedShape)& theNS,
gp_Ax1& theAx1)
{
if(theNS.IsNull() || theNS->IsEmpty()) return Standard_False;
TopoDS_Shape aShape = theNS->Get();
if(aShape.IsNull()) return Standard_False;
if(aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE) {
if (aShape.ShapeType() == TopAbs_WIRE) {
TopExp_Explorer anExplorer(aShape, TopAbs_EDGE);
aShape = anExplorer.Current();
}
const TopoDS_Edge& anEdge = TopoDS::Edge(aShape);
Standard_Real aFirst, aLast;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge,aFirst,aLast) ;
if (aCurve->IsKind (STANDARD_TYPE(Geom_Line)) ) {
Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCurve) ;
if(!aLine.IsNull()) {
theAx1 = aLine->Position() ;
return Standard_True;
}
}
}
return Standard_False;
}
//=======================================================================
//function : IsAttachment
//purpose :
//=======================================================================
Standard_Boolean DNaming::IsAttachment(const Handle(TDataStd_UAttribute)& anObj)
{
Handle(TFunction_Function) aFun = GetFirstFunction(anObj);
if(!aFun.IsNull()) {
const Standard_GUID& aGUID = aFun->GetDriverGUID();
if(aGUID == ATTCH_GUID || aGUID == XTTCH_GUID) {
return
aFun->Label().FindChild(FUNCTION_ARGUMENTS_LABEL).FindChild(ATTACH_ARG).IsAttribute(TDF_Reference::GetID());
}
}
return Standard_False;
}
//=======================================================================
//function : GetAttachmentsContext
//purpose :
//=======================================================================
Handle(TNaming_NamedShape) DNaming::GetAttachmentsContext(const Handle(TDataStd_UAttribute)& anObj)
{
Handle(TNaming_NamedShape) aNS;
Handle(TFunction_Function) aFun = GetFirstFunction(anObj);
if(!aFun.IsNull()) {
const Standard_GUID& aGUID = aFun->GetDriverGUID();
if(aGUID == ATTCH_GUID) {
const TDF_Label& aLabel = aFun->Label().FindChild(FUNCTION_ARGUMENTS_LABEL).FindChild(ATTACH_ARG);
Handle(TDF_Reference) aRef;
Handle(TFunction_Function) aFunCnt;
if(aLabel.FindAttribute(TDF_Reference::GetID(), aRef)) {
if(aRef->Get().FindAttribute(TFunction_Function::GetID(), aFunCnt)) {
const TDF_Label& aResultLabel = aFunCnt->Label().FindChild(FUNCTION_RESULT_LABEL, Standard_True);
aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS);
}
}
}
}
return aNS;
}
//=======================================================================
//function : ComputeSweepDir
//purpose : Computes direction for extrusion
//=======================================================================
Standard_Boolean DNaming::ComputeSweepDir (const TopoDS_Shape& theShape,
gp_Ax1& theAxis)
{
// Find surface
TopLoc_Location aLocation = theShape.Location();
Handle(Geom_Plane) aPlane;
if (theShape.ShapeType() == TopAbs_FACE) {
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(theShape));
#ifdef OCC_DEB
Standard_CString s = aSurf->DynamicType()->Name();
cout<<"Surface Dynamic TYPE = "<<s<<endl;
#endif
if (aSurf->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
aSurf = ((Handle(Geom_RectangularTrimmedSurface)&) aSurf)->BasisSurface();
aPlane = Handle(Geom_Plane)::DownCast(aSurf);
}
if(aPlane.IsNull()) {
BRepLib_FindSurface aFinder (theShape, 0., Standard_True);
if (!aFinder.Found()) return Standard_False;
aPlane = Handle(Geom_Plane)::DownCast(aFinder.Surface());
}
if (aPlane.IsNull()) return Standard_False;
theAxis = aPlane->Pln().Axis();
if (!aPlane->Pln().Direct()) theAxis.Reverse();
if (theShape.Orientation() == TopAbs_REVERSED) theAxis.Reverse();
return Standard_True;
}

View File

@@ -0,0 +1,498 @@
// File: DNaming_BasicCommands.cxx
// Created: Mon Jan 13 14:25:34 1997
// Author: VAUTHIER Jean-Claude
#include <DNaming.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_Data.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_LabelList.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_Tool.hxx>
#include <DDF.hxx>
#include <DDF_Data.hxx>
#include <TNaming.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_NewShapeIterator.hxx>
#include <TNaming_OldShapeIterator.hxx>
#include <TNaming_Iterator.hxx>
#include <TNaming_Tool.hxx>
#include <TNaming_MapOfNamedShape.hxx>
#include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
#include <Draw_Drawable3D.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <TopoDS_Shape.hxx>
#include <DBRep.hxx>
#include <TNaming_Builder.hxx>
#include <TDataStd_Name.hxx>
#include <TDF_TagSource.hxx>
#include <TopExp_Explorer.hxx>
#include <gp.hxx>
#include <gp_Vec.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
#include <gp_Trsf.hxx>
#include <TColStd_HArray1OfInteger.hxx>
//#ifdef WNT
#include <stdio.h>
//#endif
// POP : first Wrong Declaration : now it is correct
// second not used
//extern void DNaming_BuildMap(TDF_LabelMap& Updated, const TDF_Label& Lab);
//=======================================================================
//function : Ascendants
//purpose :
//=======================================================================
static Standard_Integer Ascendants (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n < 3) return 1;
char name[100];
Handle(TDF_Data) ND;
// Handle(TNaming_UsedShapes) US;
if (!DDF::GetDF(a[1],ND)) return 1;
// ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
TopoDS_Shape S = DBRep::Get (a[2]);
if (S.IsNull ()) return 1;
Standard_Integer T;
if (n > 3) T = atoi(a[3]);
else T = ND->Transaction ();
//TNaming_OldShapeIterator it (S, T, US);
TNaming_OldShapeIterator it (S, T, ND->Root());
Standard_Integer i = 0;
TCollection_AsciiString entry;
for (;it.More (); it.Next ()) {
S = it.Shape ();
sprintf (name,"%s_%s_%d",a[2],"old", i++);
DBRep::Set (name,it.Shape());
TDF_Label Label = it.Label ();
TDF_Tool::Entry(Label,entry);
di<<entry.ToCString()<<"\n";
}
return 0;
}
//=======================================================================
//function : Descendants
//purpose :
//=======================================================================
static Standard_Integer Descendants (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n < 3) return 1;
char name[100];
Handle(TDF_Data) ND;
// Handle(TNaming_UsedShapes) US;
if (!DDF::GetDF(a[1],ND)) return 1;
// ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
TopoDS_Shape S = DBRep::Get (a[2]);
if (S.IsNull ()) return 1;
Standard_Integer T;
if (n > 3) T = atoi(a[3]);
else T = ND->Transaction ();
TNaming_NewShapeIterator it (S, T, ND->Root());
Standard_Integer i = 0;
TCollection_AsciiString entry;
for (;it.More (); it.Next ()) {
S = it.Shape ();
sprintf (name,"%s_%s_%d",a[2],"new", i++);
DBRep::Set (name,it.Shape ());
TDF_Label Label = it.Label ();
TDF_Tool::Entry(Label,entry);
di<<entry.ToCString()<<"\n";
}
return 0;
}
//=======================================================================
//function : GetEntry
//purpose :
//=======================================================================
static Standard_Integer Getentry (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n < 3) return 1;
Handle(TDF_Data) ND;
// Handle(TNaming_UsedShapes) US;
if (!DDF::GetDF(a[1],ND)) return 1;
// ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
TopoDS_Shape S = DBRep::Get(a[2]);
if (S.IsNull()) {
di <<"Noone shape selected"<<"\n";
//di << 0;
return 0;
}
Standard_Integer Status ;
TCollection_AsciiString Name = DNaming::GetEntry(S,ND,Status);
if (Status == 0) {
di <<"E_NoName";
}
else {
di <<Name.ToCString();
if (Status == 2) {
di <<"Several shapes have the same name"<<"\n";
}
}
return 0;
}
//=======================================================================
//function : NamedShape
//purpose : retrive label of Primitive or a Generated shape
//=======================================================================
static Standard_Integer NamedShape(Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n < 3) return 1;
Handle(TDF_Data) ND;
// Handle(TNaming_UsedShapes) US;
if (!DDF::GetDF(a[1],ND)) return 1;
TopoDS_Shape SS = DBRep::Get(a[2]);
if (SS.IsNull()) {
di <<"Noone shape selected"<<"\n";
//di << 0;
return 0;
}
Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape (SS,ND->Root());
if (NS.IsNull()) {
di <<"E_NoName";
return 0;
}
TCollection_AsciiString Name; TDF_Tool::Entry(NS->Label(),Name);
di <<Name.ToCString();
return 0;
}
//=======================================================================
//function : Currentshape
//purpose :
//=======================================================================
static Standard_Integer Currentshape (Draw_Interpretor& , Standard_Integer n, const char** a)
{
if (n < 4) return 1;
Handle(TDF_Data) ND;
if (!DDF::GetDF(a[1],ND)) return 1;
Standard_CString LabelName = a[2];
TopoDS_Shape S = DNaming::CurrentShape(LabelName,ND);
if (!S.IsNull()) {
if (n == 4) DBRep::Set(a[3],S);
else DBRep::Set(a[2],S);
return 0;
}
return 0;
}
//=======================================================================
//function : Initialshape
//purpose :
//=======================================================================
static Standard_Integer Initialshape (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n < 4) return 1;
Handle(TDF_Data) ND;
if (!DDF::GetDF(a[1],ND)) return 1;
TopoDS_Shape NS = DBRep::Get(a[2]);
if (NS.IsNull()) return 1;
TDF_LabelList Labels;
TopoDS_Shape S = TNaming_Tool::InitialShape (NS,ND->Root(),Labels);
if (!S.IsNull()) {
DBRep::Set (a[3], S);
}
TDF_ListIteratorOfLabelList itL(Labels);
TCollection_AsciiString entry;
if (itL.More()) {
TDF_Tool::Entry(itL.Value(),entry);
di << entry.ToCString();
itL.Next();
}
for (; itL.More(); itL.Next()) {
TDF_Tool::Entry(itL.Value(),entry);
di <<" , "<< entry.ToCString();
}
di <<"."<<"\n";
return 0;
}
//=======================================================================
//function : GetShape
//purpose :
//=======================================================================
static Standard_Integer Exploreshape (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
char name[100];
if (n < 4) return 1;
Handle(TDF_Data) ND;
// Handle(TNaming_UsedShapes) US;
if (!DDF::GetDF(a[1],ND)) return 1;
// ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
Standard_Integer Trans = ND->Transaction();
if (n == 5) { Trans = (Standard_Integer ) atof(a[4]);}
TDF_Label Lab;
DDF::FindLabel(ND,a[2],Lab);
Handle(TNaming_NamedShape) NS;
if (!Lab.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
di <<"No shape"<<"\n";
return 0;
}
//TNaming::Print(NS->Evolution(),cout);
Standard_SStream aStream;
TNaming::Print(NS->Evolution(),aStream);
di << aStream << "\n";
Standard_Integer NbShapes = 1;
for (TNaming_Iterator itL(Lab,Trans) ; itL.More(); itL.Next()) {
if (!itL.OldShape().IsNull()) {
sprintf(name,"%s%s_%d","old",a[3],NbShapes);
DBRep::Set (name,itL.OldShape());
}
if (!itL.NewShape().IsNull()) {
sprintf(name,"%s_%d",a[3],NbShapes);
DBRep::Set (name,itL.NewShape());
}
NbShapes++;
}
di <<"\n";
if (NbShapes == 0) {
di <<"No shape"<<"\n";
}
return 0;
}
//=======================================================================
//function : GeneratedShape
//purpose : Generatedshape df shape Generationentry [drawname]
//=======================================================================
static Standard_Integer Generatedshape (Draw_Interpretor& di,
Standard_Integer nb,
const char** arg)
{
TopoDS_Shape S;
Handle(TNaming_NamedShape) A;
if (nb >= 4) {
Handle(TDF_Data) DF;
if (!DDF::GetDF(arg[1],DF)) return 1;
TopoDS_Shape Gen = DBRep::Get(arg[2]);
Handle(TNaming_NamedShape) Generation;
if (!DDF::Find(DF,arg[3],TNaming_NamedShape::GetID(),Generation)) return 1;
S = TNaming_Tool::GeneratedShape(Gen,Generation);
if (!S.IsNull()) {
if (nb == 4) DBRep::Set(arg[4],S);
else DBRep::Set(arg[3],S);
return 0;
}
}
di << "GetShape : Error" << "\n";
return 1;
}
//=======================================================================
//function : DDataStd_GetShape
//purpose :
//=======================================================================
static Standard_Integer Getshape (Draw_Interpretor& di,
Standard_Integer nb,
const char** arg)
{
TopoDS_Shape s;
Handle(TNaming_NamedShape) A;
if (nb >= 3) {
Handle(TDF_Data) DF;
if (!DDF::GetDF(arg[1],DF)) return 1;
if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1;
s = TNaming_Tool::GetShape(A);
if (!s.IsNull()) {
if (nb == 4) DBRep::Set(arg[3],s);
else DBRep::Set(arg[2],s);
return 0;
}
}
di << "DDataStd_GetShape : Error" << "\n";
return 1;
}
//=======================================================================
//function : Collect
//purpose :
//=======================================================================
static Standard_Integer Collect (Draw_Interpretor& di,
Standard_Integer nb,
const char** arg)
{
TNaming_MapOfNamedShape MNS;
Handle(TNaming_NamedShape) A;
Standard_Boolean OnlyModif = 1;
if (nb >= 3) {
Handle(TDF_Data) DF;
if (!DDF::GetDF(arg[1],DF)) return 1;
if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1;
if (nb >= 4) {
OnlyModif = atoi(arg[3]);
}
TNaming_Tool::Collect(A,MNS,OnlyModif);
for (TNaming_MapIteratorOfMapOfNamedShape it(MNS); it.More(); it.Next()) {
TCollection_AsciiString Name;
TDF_Tool::Entry(it.Key()->Label(),Name);
di <<Name.ToCString()<<" ";
}
}
return 1;
}
//=======================================================================
//function : GetCreationEntry
//purpose : retrive label of Primitive or a Generated shape
//=======================================================================
static Standard_Integer Getcreationentry (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n < 3) return 1;
Handle(TDF_Data) ND;
// Handle(TNaming_UsedShapes) US;
if (!DDF::GetDF(a[1],ND)) return 1;
// ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
TopoDS_Shape SS = DBRep::Get(a[2]);
if (SS.IsNull()) {
di <<"Noone shape selected"<<"\n";
//di << 0;
return 0;
}
TDF_LabelList Labels;
TopoDS_Shape S = TNaming_Tool::InitialShape(SS, ND->Root(), Labels);
if (S.IsNull()) {
di <<"E_NoName";
return 0;
}
Standard_Integer Status ;
TCollection_AsciiString Name = DNaming::GetEntry(S,ND,Status);
if (Status == 0) {
di <<"E_NoName";
}
else {
di <<Name.ToCString();
if (Status == 2) {
di <<"Several shapes have the same name"<<"\n";
}
}
return 0;
}
//=======================================================================
//function : ImportShape
//purpose : "ImportShape Doc entry Shape Name"
//=======================================================================
static Standard_Integer DNaming_ImportShape (Draw_Interpretor& di,
Standard_Integer nb,
const char** a)
{
if (nb >= 4) {
Handle(TDF_Data) aDF;
if(!DDF::GetDF(a[1], aDF)) return 1;
TDF_Label L;
DDF::AddLabel(aDF, a[2], L);
const TopoDS_Shape& aShape = DBRep::Get(a[3]);
if(aShape.IsNull()) return 1;
if(nb == 5) {
TDataStd_Name::Set(L, a[4]);
}
DNaming::LoadImportedShape(L, aShape);
DDF::ReturnLabel(di, L);
return 0;
}
cout << "DNaming_NewShape : Error" << endl;
return 1;
}
//=======================================================================
//function : BasicCommands
//purpose :
//=======================================================================
void DNaming::BasicCommands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
done = Standard_True;
const char* g = "Naming data commands";
// Exploration
theCommands.Add("Ascendants", "Ascendants df shape [trans]", __FILE__,Ascendants, g);
theCommands.Add("Descendants", "Descendants df shape [trans]", __FILE__,Descendants, g);
theCommands.Add("ExploreShape","ExploreShape df entry res [trans]",__FILE__,Exploreshape, g);
theCommands.Add("GetEntry", "GetEntry df shape", __FILE__,Getentry, g);
theCommands.Add("GetCreationEntry", "GetCreationEntry df shape",__FILE__,Getcreationentry,g);
theCommands.Add("NamedShape", "NamedShape df shape", __FILE__,NamedShape, g);
theCommands.Add("InitialShape","InitialShape df shape res", __FILE__,Initialshape, g);
theCommands.Add("CurrentShape","Currentshape df entry [drawname]", __FILE__,Currentshape, g);
theCommands.Add("GetShape", "GetShape df entry [drawname]", __FILE__,Getshape , g);
theCommands.Add("Collect", "Collect df entry [onlymodif 0/1]",__FILE__,Collect , g);
theCommands.Add ("GeneratedShape",
"Generatedshape df shape Generationentry [drawname]",
__FILE__,Generatedshape,g);
theCommands.Add("ImportShape",
"ImportShape Doc Shape [Name]",
__FILE__, DNaming_ImportShape, g);
}

View File

@@ -0,0 +1,57 @@
-- File: DNaming_BooleanOperationDriver.cdl
-- Created: Tue May 5 17:00:16 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class BooleanOperationDriver from DNaming inherits Driver from TFunction
---Purpose: Driver for Fuse, Cut, Common
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
BooleanOperation from BRepAlgoAPI
is
Create returns mutable BooleanOperationDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; MS : in out BooleanOperation from BRepAlgoAPI)
is private;
CheckAndLoad(me; theMkOpe : in out BooleanOperation from BRepAlgoAPI;
theFunction : Function from TFunction)
returns Boolean from Standard is private;
end BooleanOperationDriver;

View File

@@ -0,0 +1,563 @@
// File: DNaming_BooleanOperationDriver.cxx
// Created: Tue May 5 17:23:33 2009
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2009
#include <DNaming_BooleanOperationDriver.ixx>
#include <TFunction_Function.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_Integer.hxx>
#include <TFunction_Logbook.hxx>
#include <TNaming.hxx>
#include <TNaming_NamedShape.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Vertex.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Real.hxx>
#include <TDF_Label.hxx>
#include <ModelDefinitions.hxx>
#include <DNaming.hxx>
#include <TNaming_Builder.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepAlgoAPI_Common.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <BRepLib.hxx>
#include <Precision.hxx>
#include <BRepCheck_ListIteratorOfListOfStatus.hxx>
#include <BRepCheck_Result.hxx>
#include <BRepCheck_ListOfStatus.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <Adaptor3d_HCurve.hxx>
#include <GeomAbs_SurfaceType.hxx>
static Standard_Boolean FixSameParameter(const TopoDS_Shape& theShape,
BRepCheck_Analyzer& theAnalyzer,
const Standard_Boolean bIgnoreNotSPErrors = Standard_False );
static void FindSPErrorEdges(const TopoDS_Shape& theShape,
const BRepCheck_Analyzer& theAnalyzer,
TopTools_IndexedMapOfShape& theMap);
static Standard_Boolean FindOtherErrors(const TopoDS_Shape& theShape,
const BRepCheck_Analyzer& theAnalyzer,
const TopTools_IndexedMapOfShape& theMap);
//=======================================================================
//function : DNaming_BooleanOperationDriver
//purpose : Constructor
//=======================================================================
DNaming_BooleanOperationDriver::DNaming_BooleanOperationDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <log>.
//=======================================================================
void DNaming_BooleanOperationDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <log> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_BooleanOperationDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Execute the function and push in <log> the impacted labels
//=======================================================================
Standard_Integer DNaming_BooleanOperationDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
// Handle(TDataStd_UAttribute) anObject = DNaming::GetObjectFromFunction(aFunction);
// if(anObject.IsNull()) return -1;
// Handle(TNaming_NamedShape) anObjectNS = DNaming::GetObjectValue(anObject);
Handle(TFunction_Function) aPrevFun = DNaming::GetPrevFunction(aFunction);
if(aPrevFun.IsNull()) return -1;
const TDF_Label& aLab = RESPOSITION(aPrevFun);
Handle(TNaming_NamedShape) anObjectNS;
aLab.FindAttribute(TNaming_NamedShape::GetID(), anObjectNS);
if (anObjectNS.IsNull() || anObjectNS->IsEmpty()) {
#ifdef DEB
cout<<"BooleanOperationDriver:: Object is empty"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
Handle(TDataStd_UAttribute) aToolObj = DNaming::GetObjectArg(aFunction,BOOL_TOOL);
Handle(TNaming_NamedShape) aToolNS = DNaming::GetObjectValue(aToolObj);
if (aToolNS.IsNull() || aToolNS->IsEmpty()) {
#ifdef DEB
cout<<"BooleanOperationDriver:: Tool is empty"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
TopoDS_Shape aTOOL = aToolNS->Get();
TopoDS_Shape anOBJECT = anObjectNS->Get();
if (aTOOL.IsNull() || anOBJECT.IsNull()) {
#ifdef DEB
cout<<"BooleanOperationDriver:: Tool is null"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
Standard_Boolean anIsDone = Standard_False;
//case FUSE
if(aFunction->GetDriverGUID() == FUSE_GUID){
BRepAlgoAPI_Fuse aMkFuse (anOBJECT, aTOOL);
anIsDone = CheckAndLoad(aMkFuse, aFunction);
}
//case CUT
else if(aFunction->GetDriverGUID() == CUT_GUID){
BRepAlgoAPI_Cut aMkCut (anOBJECT, aTOOL);
anIsDone = CheckAndLoad(aMkCut, aFunction);
}
// case COMMON
else if(aFunction->GetDriverGUID() == COMMON_GUID){
BRepAlgoAPI_Common aMkCom (anOBJECT, aTOOL);
anIsDone = CheckAndLoad(aMkCom, aFunction);
}
else {
aFunction->SetFailure(UNSUPPORTED_FUNCTION);
return -1;
}
if(!anIsDone) return -1;
else {
theLog.SetValid(RESPOSITION(aFunction),Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
}
//===================================================================
//=======================================================================
//function : ShapeType
//purpose :
//=======================================================================
static TopAbs_ShapeEnum ShapeType(const TopoDS_Shape& theShape) {
TopAbs_ShapeEnum TypeSh = theShape.ShapeType();
if (TypeSh == TopAbs_COMPOUND || TypeSh == TopAbs_COMPSOLID) {
TopoDS_Iterator itr(theShape);
if (!itr.More()) return TypeSh;
TypeSh = ShapeType(itr.Value());
if(TypeSh == TopAbs_COMPOUND) return TypeSh;
itr.Next();
for(; itr.More(); itr.Next())
if(ShapeType(itr.Value()) != TypeSh) return TopAbs_COMPOUND;
}
return TypeSh;
}
//=====================================================================
static Standard_Boolean IsValidSurfType(const TopoDS_Face& theFace) {
BRepAdaptor_Surface anAdapt(theFace);
Handle( Adaptor3d_HCurve ) aBasisCurve;
const GeomAbs_SurfaceType& aType = anAdapt.GetType();
if(aType == GeomAbs_Sphere)
return Standard_True;
/* if(aType == GeomAbs_Cylinder || aType == GeomAbs_Cone || Type == GeomAbs_Sphere)
return Standard_True;
else if(aType == GeomAbs_SurfaceOfRevolution){
aBasisCurve = anAdapt.BasisCurve();
if (aBasisCurve->GetType() == GeomAbs_Line)
return Standard_True;
}
else if(aType == GeomAbs_SurfaceOfExtrusion) {
aBasisCurve = anAdapt.BasisCurve();
if (aBasisCurve->GetType() == GeomAbs_Circle || aBasisCurve->GetType() == GeomAbs_Ellipse)
return Standard_True;
}
*/
#ifdef DEB
//ModDbgTools_Write(theFace, "Surf");
#endif
return Standard_False;
}
//=======================================================================
//function : IsWRCase
//purpose :
//=======================================================================
static Standard_Boolean IsWRCase(const BRepAlgoAPI_BooleanOperation& MS) {
const TopoDS_Shape& ObjSh = MS.Shape1();
const TopoDS_Shape& ToolSh = MS.Shape2();
const TopAbs_ShapeEnum& Type1 = ShapeType(ObjSh);
if(Type1 == TopAbs_COMPOUND || Type1 > TopAbs_FACE) return Standard_False;
const TopAbs_ShapeEnum& Type2 = ShapeType(ToolSh);
if(Type2 == TopAbs_COMPOUND || Type2 > TopAbs_FACE) return Standard_False;
TopTools_ListOfShape aList;
if(Type1 != TopAbs_FACE) {
TopExp_Explorer anExp(ObjSh, TopAbs_FACE);
for(;anExp.More();anExp.Next()) {
if(IsValidSurfType(TopoDS::Face(anExp.Current())))
aList.Append(anExp.Current());
}
} else
if(IsValidSurfType(TopoDS::Face(ObjSh)))
aList.Append(ObjSh);
if(aList.Extent() == 0) {
if(Type2 != TopAbs_FACE) {
TopExp_Explorer anExp(ToolSh, TopAbs_FACE);
for(;anExp.More();anExp.Next()) {
if(IsValidSurfType(TopoDS::Face(anExp.Current())))
aList.Append(anExp.Current());
}
} else
if(IsValidSurfType(TopoDS::Face(ToolSh)))
aList.Append(ToolSh);
}
if(aList.Extent() > 0) return Standard_True;
return Standard_False;
}
//=======================================================================
//function : LoadNamingDS
//purpose :
//=======================================================================
void DNaming_BooleanOperationDriver::LoadNamingDS (const TDF_Label& theResultLabel,
BRepAlgoAPI_BooleanOperation& MS) const
{
const TopoDS_Shape& ResSh = MS.Shape();
const TopoDS_Shape& ObjSh = MS.Shape1();
const TopoDS_Shape& ToolSh = MS.Shape2();
if (ResSh.IsNull()) {
#ifdef DEB
cout<<"LoadFuseNamingDS: The result of the boolean operation is null"<<endl;
#endif
return;
}
// LoadResult
DNaming::LoadResult(theResultLabel, MS);
TopTools_DataMapOfShapeShape SubShapes;
TopExp_Explorer Exp(ResSh, TopAbs_FACE);
for (; Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
// Naming of modified faces:
TNaming_Builder modFB (theResultLabel.NewChild()); //FindChild(1,Standard_True));
DNaming::LoadAndOrientModifiedShapes (MS, ObjSh, TopAbs_FACE, modFB,SubShapes);
DNaming::LoadAndOrientModifiedShapes (MS, ToolSh, TopAbs_FACE, modFB, SubShapes);
// Naming of deleted faces:
if(MS.HasDeleted()){
TNaming_Builder delB (theResultLabel.NewChild()); // FindChild(2,Standard_True));
DNaming::LoadDeletedShapes (MS, ObjSh, TopAbs_FACE, delB);
DNaming::LoadDeletedShapes (MS, ToolSh, TopAbs_FACE, delB);
}
if(IsWRCase(MS)) {
// Edges
Exp.Init(ResSh, TopAbs_EDGE);
for (; Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
const TopTools_ListOfShape& aList = MS.SectionEdges();
Standard_Boolean theCase(Standard_False);
TopTools_MapOfShape aView;
if(aList.Extent() > 0 && aList.Extent() < 3)
theCase = Standard_True;
TopTools_ListIteratorOfListOfShape it(aList);
for(;it.More();it.Next()) {
TopoDS_Shape newShape = it.Value();
if (SubShapes.IsBound(newShape))
newShape.Orientation((SubShapes(newShape)).Orientation());
TNaming_Builder secED (theResultLabel.NewChild());
secED.Generated(newShape);
if(theCase) {
TopoDS_Vertex Vfirst, Vlast;
TopExp::Vertices(TopoDS::Edge(newShape), Vfirst, Vlast, Standard_True);
if(aView.Add(Vfirst)) {
TNaming_Builder secV (theResultLabel.NewChild());
secV.Generated(Vfirst);
}
if(aView.Add(Vlast)) {
TNaming_Builder secV (theResultLabel.NewChild());
secV.Generated(Vlast);
}
}
}
}
}
//=======================================================================
//function : CheckAndLoad
//purpose : checks result of operation and performs Topological Naming
//=======================================================================
Standard_Boolean DNaming_BooleanOperationDriver::CheckAndLoad
(BRepAlgoAPI_BooleanOperation& theMkOpe,
const Handle(TFunction_Function)& theFunction) const
{
if (theMkOpe.IsDone() && !theMkOpe.Shape().IsNull()) {
#ifdef MDTV_DEB
Standard_CString aFileName = "BoolOp.brep";
Write(theMkOpe.Shape(), aFileName);
#endif
if (theMkOpe.Shape().ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator anItr(theMkOpe.Shape());
if(!anItr.More()) {
theFunction->SetFailure(NULL_RESULT);
return Standard_False;
}
}
BRepCheck_Analyzer aCheck (theMkOpe.Shape());
Standard_Boolean aResIsValid = Standard_True;
if(!aCheck.IsValid(theMkOpe.Shape()))
aResIsValid = FixSameParameter(theMkOpe.Shape(), aCheck);
if (aResIsValid) {
const TDF_Label& aResultLabel = RESPOSITION(theFunction);
if(theFunction->GetDriverGUID() == FUSE_GUID) {
LoadNamingDS(RESPOSITION(theFunction), theMkOpe);
}
else if(theFunction->GetDriverGUID() == CUT_GUID) {
LoadNamingDS(RESPOSITION(theFunction), theMkOpe); // the same naming only for case of solids
} else if(theFunction->GetDriverGUID() == COMMON_GUID) {
LoadNamingDS(RESPOSITION(theFunction), theMkOpe);
}
theFunction->SetFailure(DONE);
return Standard_True;
} else {
theFunction->SetFailure(RESULT_NOT_VALID);
return Standard_False;
}
}
theFunction->SetFailure(ALGO_FAILED);
return Standard_False;
}
// ------------------------------------------------------------------------
// static function: FixSameParameter
// purpose:
// ------------------------------------------------------------------------
Standard_Boolean FixSameParameter(const TopoDS_Shape& theShape,
BRepCheck_Analyzer& theAnalyzer,
const Standard_Boolean bIgnoreNotSPErrors) {
Standard_Integer bDoFix = Standard_True;
TopTools_IndexedMapOfShape aMapE;
FindSPErrorEdges(theShape, theAnalyzer, aMapE);
if(!bIgnoreNotSPErrors) {
if(FindOtherErrors(theShape, theAnalyzer, aMapE)) {
bDoFix = Standard_False;
}
}
if(bDoFix) {
Standard_Integer i = 0;
for(i = 1; i <= aMapE.Extent(); i++) {
const TopoDS_Shape& aE = aMapE(i);
BRepLib::SameParameter(aE, Precision::Confusion(), Standard_True);
}
if(!aMapE.IsEmpty()) {
theAnalyzer.Init(theShape);
return theAnalyzer.IsValid();
}
}
return Standard_False;
}
// ------------------------------------------------------------------------
// static function: FindSPErrorEdges
// purpose:
// ------------------------------------------------------------------------
void FindSPErrorEdges(const TopoDS_Shape& theShape,
const BRepCheck_Analyzer& theAnalyzer,
TopTools_IndexedMapOfShape& theMap) {
BRepCheck_ListIteratorOfListOfStatus itl;
TopoDS_Iterator anIt(theShape);
for (; anIt.More(); anIt.Next()) {
FindSPErrorEdges(anIt.Value(), theAnalyzer, theMap);
}
if(theShape.ShapeType() == TopAbs_FACE) {
TopExp_Explorer anExpE(theShape, TopAbs_EDGE);
for(; anExpE.More(); anExpE.Next()) {
Handle(BRepCheck_Result) aResult = theAnalyzer.Result(anExpE.Current());
if(aResult.IsNull() || theMap.Contains(anExpE.Current()))
continue;
for (aResult->InitContextIterator();
aResult->MoreShapeInContext();
aResult->NextShapeInContext()) {
if (aResult->ContextualShape().IsSame(theShape)) {
itl.Initialize(aResult->StatusOnShape());
for(; itl.More(); itl.Next()) {
if((itl.Value() == BRepCheck_InvalidSameParameterFlag) ||
(itl.Value() == BRepCheck_InvalidCurveOnSurface)) {
theMap.Add(anExpE.Current());
break;
}
}
}
}
}
}
else if(theShape.ShapeType() == TopAbs_EDGE) {
Handle(BRepCheck_Result) aResult = theAnalyzer.Result(theShape);
itl.Initialize(aResult->Status());
for(; itl.More(); itl.Next()) {
if((itl.Value() == BRepCheck_InvalidSameParameterFlag) ||
(itl.Value() == BRepCheck_InvalidCurveOnSurface)) {
theMap.Add(theShape);
break;
}
}
}
}
// ------------------------------------------------------------------------
// static function: FindOtherErrors
// purpose:
// ------------------------------------------------------------------------
Standard_Boolean FindOtherErrors(const TopoDS_Shape& theShape,
const BRepCheck_Analyzer& theAnalyzer,
const TopTools_IndexedMapOfShape& theMap) {
Standard_Boolean bOtherFound = Standard_False;
BRepCheck_ListIteratorOfListOfStatus itl;
TopoDS_Iterator anIt(theShape);
for (; anIt.More(); anIt.Next()) {
if(FindOtherErrors(anIt.Value(), theAnalyzer, theMap))
return Standard_True;
}
Handle(BRepCheck_Result) aResult = theAnalyzer.Result(theShape);
if (!aResult.IsNull()) {
if(!theMap.Contains(theShape) && !aResult->Status().IsEmpty()) {
if(aResult->Status().First() != BRepCheck_NoError) {
bOtherFound = Standard_True;
//
TopExp_Explorer anExpF(theShape, TopAbs_FACE);
for(; anExpF.More(); anExpF.Next()) {
TopExp_Explorer anExpE(anExpF.Current(), TopAbs_EDGE);
for(; anExpE.More(); anExpE.Next()) {
Handle(BRepCheck_Result) aResultE = theAnalyzer.Result(anExpE.Current());
if(aResultE.IsNull())
continue;
bOtherFound = Standard_False;
for (aResultE->InitContextIterator();
aResultE->MoreShapeInContext();
aResultE->NextShapeInContext()) {
if (aResultE->ContextualShape().IsSame(anExpF.Current()) ||
aResultE->ContextualShape().IsSame(theShape)) {
itl.Initialize(aResultE->StatusOnShape());
if(!itl.More())
continue;
if(itl.Value() != BRepCheck_NoError) {
if(theMap.Contains(anExpE.Current())) {
for(; itl.More(); itl.Next()) {
if((itl.Value() != BRepCheck_InvalidSameParameterFlag) &&
(itl.Value() != BRepCheck_InvalidCurveOnSurface) &&
(itl.Value() != BRepCheck_NoError)) {
return Standard_True;
}
}
}
else {
return Standard_True;
}
}
}
}
}
}
//
if(!bOtherFound) {
for (aResult->InitContextIterator();
!bOtherFound && aResult->MoreShapeInContext();
aResult->NextShapeInContext()) {
if(!aResult->StatusOnShape().IsEmpty()) {
bOtherFound = (aResult->StatusOnShape().First() != BRepCheck_NoError);
}
}
}
}
else {
TopAbs_ShapeEnum aType = theShape.ShapeType();
if((aType == TopAbs_VERTEX) ||
(aType == TopAbs_EDGE) ||
(aType == TopAbs_WIRE) ||
(aType == TopAbs_FACE) ||
(aType == TopAbs_SHELL)) {
for (aResult->InitContextIterator();
aResult->MoreShapeInContext();
aResult->NextShapeInContext()) {
if(!aResult->StatusOnShape().IsEmpty()) {
if(aResult->StatusOnShape().First() != BRepCheck_NoError) {
return Standard_True;
}
}
}
}
}
}
else {
itl.Initialize(aResult->Status());
for(; itl.More(); itl.Next()) {
if((itl.Value() != BRepCheck_InvalidSameParameterFlag) &&
(itl.Value() != BRepCheck_InvalidCurveOnSurface) &&
(itl.Value() != BRepCheck_NoError)) {
return Standard_True;
}
}
}
}
return bOtherFound;
}

View File

@@ -0,0 +1,49 @@
-- File: DNaming_BoxDriver.cdl
-- Created: Wed Apr 29 18:57:50 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class BoxDriver from DNaming inherits Driver from TFunction
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
MakeBox from BRepPrimAPI
is
Create returns mutable BoxDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; mkBox : in out MakeBox from BRepPrimAPI)
is private;
end BoxDriver;

View File

@@ -0,0 +1,133 @@
// File: DNaming_BoxDriver.cxx
// Created: Wed Apr 29 19:00:56 2009
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2009
#include <DNaming_BoxDriver.ixx>
#include <TFunction_Function.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_Integer.hxx>
#include <TFunction_Logbook.hxx>
#include <TNaming.hxx>
#include <TNaming_NamedShape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Solid.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Real.hxx>
#include <TDF_Label.hxx>
#include <ModelDefinitions.hxx>
#include <DNaming.hxx>
#include <TNaming_Builder.hxx>
//=======================================================================
//function : DNaming_BoxDriver
//purpose : Constructor
//=======================================================================
DNaming_BoxDriver::DNaming_BoxDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <log>.
//=======================================================================
void DNaming_BoxDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <log> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_BoxDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Execute the function and push in <log> the impacted labels
//=======================================================================
Standard_Integer DNaming_BoxDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
// perform calculations
Standard_Real aDX = DNaming::GetReal(aFunction,BOX_DX)->Get();
Standard_Real aDY = DNaming::GetReal(aFunction,BOX_DY)->Get();
Standard_Real aDZ = DNaming::GetReal(aFunction,BOX_DZ)->Get();
Handle(TNaming_NamedShape) aPrevBox = DNaming::GetFunctionResult(aFunction);
// Save location
TopLoc_Location aLocation;
if (!aPrevBox.IsNull() && !aPrevBox->IsEmpty()) {
aLocation = aPrevBox->Get().Location();
}
BRepPrimAPI_MakeBox aMakeBox(aDX, aDY, aDZ);
aMakeBox.Build();
if (!aMakeBox.IsDone())
{
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
TopoDS_Shape aResult = aMakeBox.Solid();
BRepCheck_Analyzer aCheck(aResult);
if (!aCheck.IsValid (aResult))
{
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
// Naming
LoadNamingDS(RESPOSITION(aFunction),aMakeBox);
// restore location
if(!aLocation.IsIdentity())
TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
theLog.SetValid(RESPOSITION(aFunction), Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=======================================================================
//function : LoadAndName
//purpose :
//=======================================================================
void DNaming_BoxDriver::LoadNamingDS (const TDF_Label& theResultLabel,
BRepPrimAPI_MakeBox& MS) const
{
TNaming_Builder Builder (theResultLabel);
Builder.Generated (MS.Solid());
//Load the faces of the box :
TopoDS_Face BottomFace = MS.BottomFace ();
TNaming_Builder BOF (theResultLabel.FindChild(1,Standard_True));
BOF.Generated (BottomFace);
TopoDS_Face TopFace = MS.TopFace ();
TNaming_Builder TF (theResultLabel.FindChild(2,Standard_True));
TF.Generated (TopFace);
TopoDS_Face FrontFace = MS.FrontFace ();
TNaming_Builder FF (theResultLabel.FindChild(3,Standard_True));
FF.Generated (FrontFace);
TopoDS_Face RightFace = MS.RightFace ();
TNaming_Builder RF (theResultLabel.FindChild(4,Standard_True));
RF.Generated (RightFace);
TopoDS_Face BackFace = MS.BackFace ();
TNaming_Builder BF (theResultLabel.FindChild(5,Standard_True));
BF.Generated (BackFace);
TopoDS_Face LeftFace = MS.LeftFace ();
TNaming_Builder LF (theResultLabel.FindChild(6,Standard_True));
LF.Generated (LeftFace);
}

View File

@@ -0,0 +1,52 @@
-- File: DNaming_CylinderDriver.cdl
-- Created: Mon May 4 11:31:37 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class CylinderDriver from DNaming inherits Driver from TFunction
---Purpose: Computes Cylinder function
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
MakeCylinder from BRepPrimAPI
is
Create returns mutable CylinderDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; mkCyl : in out MakeCylinder from BRepPrimAPI)
is private;
end CylinderDriver;

View File

@@ -0,0 +1,193 @@
// File: DNaming_CylinderDriver.cxx
// Created: Mon May 4 12:02:03 2009
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2009
#include <DNaming_CylinderDriver.ixx>
#include <TFunction_Function.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_Integer.hxx>
#include <TFunction_Logbook.hxx>
#include <TNaming.hxx>
#include <TNaming_NamedShape.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Solid.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Real.hxx>
#include <TDF_Label.hxx>
#include <ModelDefinitions.hxx>
#include <DNaming.hxx>
#include <TNaming_Builder.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TopoDS.hxx>
#include <gp_Lin.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_Line.hxx>
//=======================================================================
//function : DNaming_CylinderDriver
//purpose : Constructor
//=======================================================================
DNaming_CylinderDriver::DNaming_CylinderDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <log>.
//=======================================================================
void DNaming_CylinderDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <log> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_CylinderDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Execute the function and push in <log> the impacted labels
//=======================================================================
Standard_Integer DNaming_CylinderDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
Standard_Real aRadius = DNaming::GetReal(aFunction,CYL_RADIUS)->Get();
Standard_Real aHeight = DNaming::GetReal(aFunction,CYL_HEIGHT)->Get();
Handle(TDataStd_UAttribute) anObject = DNaming::GetObjectArg(aFunction,CYL_AXIS);
Handle(TNaming_NamedShape) aNSAxis = DNaming::GetObjectValue(anObject);
if (aNSAxis->IsEmpty()) {
#ifdef DEB
cout<<"CylinderDriver:: Axis is empty"<<endl;
#endif
aFunction->SetFailure(WRONG_AXIS);
return -1;
}
TopoDS_Shape aTopoDSAxis = aNSAxis->Get();
if (aTopoDSAxis.IsNull()) {
#ifdef DEB
cout<<"CylinderDriver:: Axis is null"<<endl;
#endif
aFunction->SetFailure(WRONG_AXIS);
return -1;
}
// Creation of gp axis (gp_Ax2):
if (aTopoDSAxis.ShapeType() != TopAbs_EDGE && aTopoDSAxis.ShapeType() != TopAbs_WIRE) {
#ifdef DEB
cout<<"CylinderDriver:: Wrong axis, ShapeType = " << aTopoDSAxis.ShapeType() <<endl;
#endif
aFunction->SetFailure(WRONG_AXIS);
return -1;
}
gp_Ax2 anAxis;
if (aTopoDSAxis.ShapeType() == TopAbs_WIRE) {
TopExp_Explorer anExplorer(aTopoDSAxis, TopAbs_EDGE);
aTopoDSAxis = anExplorer.Current();
}
BRepAdaptor_Curve aCurveAda(TopoDS::Edge(aTopoDSAxis));
if (aCurveAda.GetType() == GeomAbs_Line) {
gp_Lin aLin = aCurveAda.Line();
anAxis = gp_Ax2(aLin.Location(), aLin.Direction());
if(!aTopoDSAxis.Infinite()) {
TopoDS_Vertex V1, V2;
TopExp::Vertices(TopoDS::Edge(aTopoDSAxis), V1, V2);
gp_Pnt aP1 = BRep_Tool::Pnt(V1);
anAxis.SetLocation(aP1);
}
} else {
#ifdef DEB
cout<<"CylinderDriver:: I don't support wires for a while"<<endl;
#endif
aFunction->SetFailure(WRONG_AXIS);
return -1;
}
Handle(TNaming_NamedShape) aPrevCyl = DNaming::GetFunctionResult(aFunction);
// Save location
TopLoc_Location aLocation;
if (!aPrevCyl.IsNull() && !aPrevCyl->IsEmpty()) {
aLocation = aPrevCyl->Get().Location();
}
BRepPrimAPI_MakeCylinder aMakeCylinder(anAxis, aRadius, aHeight);
aMakeCylinder.Build();
if (!aMakeCylinder.IsDone()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
TopoDS_Shape aResult = aMakeCylinder.Solid();
BRepCheck_Analyzer aCheck(aResult);
if (!aCheck.IsValid(aResult)) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
// Naming
LoadNamingDS(RESPOSITION(aFunction), aMakeCylinder);
// restore location
if(!aLocation.IsIdentity())
TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
theLog.SetValid(RESPOSITION(aFunction), Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=======================================================================
//function : LoadAndName
//purpose :
//=======================================================================
void DNaming_CylinderDriver::LoadNamingDS (const TDF_Label& theResultLabel,
BRepPrimAPI_MakeCylinder& MS) const
{
TNaming_Builder Builder (theResultLabel);
Builder.Generated (MS.Solid());
BRepPrim_Cylinder& S = MS.Cylinder();
//Load faces of the Cyl :
if (S.HasBottom()) {
TopoDS_Face BottomFace = S.BottomFace ();
TNaming_Builder BOF (theResultLabel.FindChild(1,Standard_True));
BOF.Generated (BottomFace);
}
if (S.HasTop()) {
TopoDS_Face TopFace = S.TopFace ();
TNaming_Builder TOF (theResultLabel.FindChild(2,Standard_True));
TOF.Generated (TopFace);
}
TopoDS_Face LateralFace = S.LateralFace();
TNaming_Builder LOF (theResultLabel.FindChild(3,Standard_True));
LOF.Generated(LateralFace);
if (S.HasSides()) {
TopoDS_Face StartFace = S.StartFace();
TNaming_Builder SF(theResultLabel.FindChild(4,Standard_True));
SF.Generated(StartFace);
TopoDS_Face EndFace = S.EndFace();
TNaming_Builder EF(theResultLabel.FindChild(5,Standard_True));
EF.Generated(EndFace);
}
}

View File

@@ -0,0 +1,54 @@
-- File: DNaming_FilletDriver.cdl
-- Created: Wed May 6 14:43:43 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class FilletDriver from DNaming inherits Driver from TFunction
---Purpose:
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
MakeFillet from BRepFilletAPI,
Shape from TopoDS
is
Create returns mutable FilletDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; mkFillet : in out MakeFillet from BRepFilletAPI;
theContext : Shape from TopoDS)
is private;
end FilletDriver;

View File

@@ -0,0 +1,203 @@
// File: DNaming_FilletDriver.cxx
// Created: Wed May 6 14:55:34 2009
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2009
#include <DNaming_FilletDriver.ixx>
#include <Precision.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Real.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <BRepAlgo.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Edge.hxx>
#include <TDF_Label.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_Integer.hxx>
#include <TNaming.hxx>
#include <TNaming_Iterator.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TFunction_Logbook.hxx>
#include <TFunction_Function.hxx>
#include <DNaming.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <ModelDefinitions.hxx>
//=======================================================================
//function : FilletDriver
//purpose : Constructor
//=======================================================================
DNaming_FilletDriver::DNaming_FilletDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <log>.
//=======================================================================
void DNaming_FilletDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <log> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_FilletDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Execute the function and push in <log> the impacted labels
//=======================================================================
Standard_Integer DNaming_FilletDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
Handle(TFunction_Function) aPrevFun = DNaming::GetPrevFunction(aFunction);
if(aPrevFun.IsNull()) return -1;
const TDF_Label& aLab = RESPOSITION(aPrevFun);
Handle(TNaming_NamedShape) aContextNS;
aLab.FindAttribute(TNaming_NamedShape::GetID(), aContextNS);
if (aContextNS.IsNull() || aContextNS->IsEmpty()) {
#ifdef DEB
cout<<"FilletDriver:: Context is empty"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
const Standard_Real aRadius = DNaming::GetReal(aFunction,FILLET_RADIUS)->Get();
const ChFi3d_FilletShape aSurfaceType =
(ChFi3d_FilletShape) DNaming::GetInteger(aFunction,FILLET_SURFTYPE)->Get();
if(aRadius < Precision::Confusion()) {
aFunction->SetFailure(WRONG_ARGUMENT);
#ifdef DEB
cout << "FilletDriver:: Radius < Precision::Confusion" << endl;
#endif
return -1;
}
Handle(TDataStd_UAttribute) aPathObj = DNaming::GetObjectArg(aFunction,FILLET_PATH);
Handle(TNaming_NamedShape) aPathNS = DNaming::GetObjectValue(aPathObj);
if (aPathNS.IsNull() || aPathNS->IsEmpty()) {
#ifdef DEB
cout<<"FilletDriver:: Path is empty"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
TopoDS_Shape aPATH = aPathNS->Get();
TopoDS_Shape aCONTEXT = aContextNS->Get();
if (aPATH.IsNull() || aCONTEXT.IsNull()) {
#ifdef DEB
cout<<"FilletDriver:: Path or Context is null"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
TopExp_Explorer expl;
TopTools_MapOfShape View;
BRepFilletAPI_MakeFillet aMkFillet(aCONTEXT, aSurfaceType);
if(aPATH.ShapeType() != TopAbs_EDGE && aPATH.ShapeType() != TopAbs_FACE) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
if(aPATH.ShapeType() == TopAbs_FACE) {
for (expl.Init(aPATH, TopAbs_EDGE); expl.More(); expl.Next()){
const TopoDS_Edge& anEdge = TopoDS::Edge(expl.Current());
if (!View.Add(anEdge)) continue;
else
aMkFillet.Add(aRadius, anEdge); //Edge
}
}
else {
const TopoDS_Edge& anEdge = TopoDS::Edge(aPATH);
aMkFillet.Add(aRadius, anEdge); //Edge
}
aMkFillet.Build();
if (!aMkFillet.IsDone()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
TopTools_ListOfShape aLarg;
aLarg.Append(aCONTEXT);
if (!BRepAlgo::IsValid(aLarg, aMkFillet.Shape(),Standard_False,Standard_False)) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
// Naming
LoadNamingDS(RESPOSITION(aFunction), aMkFillet, aCONTEXT);
theLog.SetValid(RESPOSITION(aFunction),Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=======================================================================
//function : LoadAndName
//purpose :
//=======================================================================
void DNaming_FilletDriver::LoadNamingDS (const TDF_Label& theResultLabel,
BRepFilletAPI_MakeFillet& theMkFillet,
const TopoDS_Shape& theContext) const
{
TNaming_Builder aBuilder (theResultLabel);
TopoDS_Shape aResult = theMkFillet.Shape();
if (aResult.ShapeType() == TopAbs_COMPOUND) {
Standard_Integer nbSubResults = 0;
TopoDS_Iterator itr(aResult);
for (; itr.More(); itr.Next()) nbSubResults++;
if (nbSubResults == 1) {
itr.Initialize(aResult);
if (itr.More()) aResult = itr.Value();
}
}
if (aResult.IsNull()) aBuilder.Generated(aResult);
else
aBuilder.Modify(theContext, aResult);
TopTools_DataMapOfShapeShape SubShapes;
for (TopExp_Explorer Exp(aResult, TopAbs_FACE); Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
//New faces generated from edges
TNaming_Builder anEdgeBuilder(theResultLabel.FindChild(1,Standard_True));
DNaming::LoadAndOrientGeneratedShapes(theMkFillet, theContext, TopAbs_EDGE, anEdgeBuilder, SubShapes);
//Faces of the initial shape modified by theMkFillet
TNaming_Builder aFacesBuilder(theResultLabel.FindChild(2,Standard_True));
DNaming::LoadAndOrientModifiedShapes(theMkFillet, theContext, TopAbs_FACE, aFacesBuilder, SubShapes);
//New faces generated from vertices (if exist)
TNaming_Builder aVFacesBuilder(theResultLabel.FindChild(3,Standard_True));
DNaming::LoadAndOrientGeneratedShapes(theMkFillet, theContext, TopAbs_VERTEX, aVFacesBuilder, SubShapes);
//Deleted faces of the initial shape
TNaming_Builder aDelBuilder(theResultLabel.FindChild(4,Standard_True));
DNaming::LoadDeletedShapes(theMkFillet, theContext, TopAbs_FACE, aDelBuilder);
}

View File

@@ -0,0 +1,54 @@
-- File: DNaming_Line3DDriver.cdl
-- Created: Fri Feb 26 15:51:03 2010
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
-- <szy@petrox.nnov.matra-dtv.fr>
---Copyright: Open CasCade SA 2010
class Line3DDriver from DNaming inherits Driver from TFunction
---Purpose: Computes Line 3D function
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
Wire from TopoDS,
Array1OfShape from TopTools
is
Create returns mutable Line3DDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; theWire : Wire from TopoDS;
theVertexes : Array1OfShape from TopTools;
isClosed : Boolean from Standard = Standard_False) is private;
---Purpose: Loads a Line3D in a data framework
end Line3DDriver;

View File

@@ -0,0 +1,311 @@
// File: DNaming_Line3DDriver.cxx
// Created: Fri Feb 26 16:54:50 2010
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2010
#include <DNaming_Line3DDriver.ixx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <gp_Trsf.hxx>
#include <Precision.hxx>
#include <Standard_GUID.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepAlgo.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomAPI_Interpolate.hxx>
#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <TopLoc_Location.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <TopTools_Array1OfShape.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <TopAbs.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TDF_Label.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_Integer.hxx>
#include <TNaming.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TFunction_Logbook.hxx>
#include <TFunction_Function.hxx>
#include <DNaming.hxx>
#include <ModelDefinitions.hxx>
#ifdef WNT
#define EXCEPTION ...
#else
#define EXCEPTION Standard_Failure
#endif
//#define MDTV_DEB 1
#ifdef MDTV_DEB
#include <TDF_Tool.hxx>
#include <BRepTools.hxx>
static void Write(const TopoDS_Shape& shape,
const Standard_CString filename)
{
ofstream save;
save.open(filename);
save << "DBRep_DrawableShape" << endl << endl;
if(!shape.IsNull()) BRepTools::Write(shape, save);
save.close();
}
#endif
inline static Standard_GUID getLine3DNamingVersionID() {
static Standard_GUID anID("BB74BAD5-7AAD-44b4-850F-05416F09B28E");
return anID;
}
//=======================================================================
//function : DNaming_Line3DDriver
//purpose : Constructor
//=======================================================================
DNaming_Line3DDriver::DNaming_Line3DDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <theLog>.
//=======================================================================
void DNaming_Line3DDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <theLog> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_Line3DDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Execute the function
//=======================================================================
Standard_Integer DNaming_Line3DDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
aFunction->SetFailure(NOTDONE);
Handle(TNaming_NamedShape) aPrevILine3D = DNaming::GetFunctionResult(aFunction);
// Save location
TopLoc_Location aLocation;
if (!aPrevILine3D.IsNull() && !aPrevILine3D->IsEmpty()) {
aLocation = aPrevILine3D->Get().Location();
}
const Standard_Integer aType = DNaming::GetInteger(aFunction, LINE3D_TYPE)->Get();
Standard_Boolean isClosed(aType);
Standard_Integer aCounter(0), aLength = DNaming::GetInteger(aFunction, LINE3D_PNTNB)->Get();
if(aLength < 2) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
Handle(TNaming_NamedShape) aNS1, aNS2;
BRepBuilderAPI_MakeWire aMakeWire;
TopoDS_Wire aWire;
TopoDS_Shape aShape1, aShape2;
TopTools_Array1OfShape anArV(1,aLength); //aLength - number of points
for(aCounter = 1; aCounter <= aLength-1; aCounter++) {
Handle(TDataStd_UAttribute) aRefP1 = DNaming::GetObjectArg(aFunction, (LINE3D_TYPE + aCounter));
aNS1 = DNaming::GetObjectValue(aRefP1);
Handle(TDataStd_UAttribute) aRefP2 = DNaming::GetObjectArg(aFunction, (LINE3D_TYPE + aCounter +1));
aNS2 = DNaming::GetObjectValue(aRefP2);
#ifdef MDTV_DEB
if(!aNS1->IsEmpty()) {
aShape1 = aNS1->Get();
gp_Pnt aDebPoint = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
// cout << aCounter << " X = " << aDebPoint.X() << " Y = " << aDebPoint.Y() << " Z = " << aDebPoint.Z() << endl;
} else
cout << " Line3DDriver:: NS1 is empty" << endl;
if(!aNS2->IsEmpty()) {
aShape2 = aNS2->Get();
gp_Pnt aDebPoint = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
// cout << aCounter+1 << " X = " << aDebPoint.X() << " Y = " << aDebPoint.Y() << " Z = " << aDebPoint.Z() << endl;
} else
cout << " Line3DDriver:: NS2 is empty" << endl;
#endif
if(aNS1->IsEmpty() || aNS2->IsEmpty() ||
aNS1->Get().IsNull() || aNS2->Get().IsNull()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
aShape1 = aNS1->Get();
aShape2 = aNS2->Get();
#ifdef MDTV_DEB
gp_Pnt aDebPoint = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
// cout << aCounter << " X = " << aDebPoint.X() << " Y = " << aDebPoint.Y() << " Z = " << aDebPoint.Z() << endl;
aDebPoint = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
// cout << aCounter+1 << " X = " << aDebPoint.X() << " Y = " << aDebPoint.Y() << " Z = " << aDebPoint.Z() << endl;
#endif
if(aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_VERTEX) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
BRepBuilderAPI_MakeEdge aMakeEdge(TopoDS::Vertex(aShape1), TopoDS::Vertex(aShape2));
if(aMakeEdge.IsDone()) {
anArV.SetValue(aCounter, aShape1);
anArV.SetValue(aCounter+1, aShape2);
aMakeWire.Add(aMakeEdge.Edge());
}
}
// } else // closed
if(isClosed) {
Handle(TDataStd_UAttribute) aRefP1 = DNaming::GetObjectArg(aFunction, (LINE3D_TYPE + 1));
aNS1 = DNaming::GetObjectValue(aRefP1);
aShape1 = aNS1->Get();
BRepBuilderAPI_MakeEdge aMakeEdge(TopoDS::Vertex(aShape2), TopoDS::Vertex(aShape1));
if(aMakeEdge.IsDone()) aMakeWire.Add(aMakeEdge.Edge());
}
if(aMakeWire.IsDone()) aWire = aMakeWire.Wire();
if(aWire.IsNull()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
if (!BRepAlgo::IsValid(aWire)) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
TDF_Label aResultLabel = RESPOSITION(aFunction); //aFunction->GetResult()->Label();
try {
LoadNamingDS(aResultLabel, aWire, anArV, isClosed);
} catch (EXCEPTION) {
aFunction->SetFailure(NAMING_FAILED);
return -1;
}
// restore location
if(!aLocation.IsIdentity())
TNaming::Displace(aResultLabel, aLocation, Standard_True);
theLog.SetValid(aResultLabel, Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=======================================================================
//function : LoadNamingDS
//purpose : Loads a Line3D in a data framework
//=======================================================================
void DNaming_Line3DDriver::LoadNamingDS (const TDF_Label& theResultLabel,
const TopoDS_Wire& theWire,
const TopTools_Array1OfShape& theArV,
const Standard_Boolean isClosed) const
{
if(theWire.IsNull()) return;
//Wire
TNaming_Builder aWBuilder(theResultLabel);
aWBuilder.Generated(theWire);
#ifdef MDTV_DEB
TDataStd_Name::Set(theResultLabel, "Line3DCurve");
#endif
Standard_Integer aLength = theArV.Length();
if(aLength < 2) return;
TopoDS_Shape aShape;
TopTools_Array1OfShape anArE(1,aLength);
TopoDS_Vertex aFirst, aLast;
for(Standard_Integer i = 1;i < aLength;i++) {
gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(theArV.Value(i)));
gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(theArV.Value(i+1)));
Standard_Boolean aFound = Standard_False;
TopExp_Explorer anExp(theWire,TopAbs_EDGE);
for(;anExp.More();anExp.Next()) {
const TopoDS_Edge& anE = TopoDS::Edge(anExp.Current());
TopoDS_Vertex aV, aV1, aV2;
TopExp::Vertices(anE, aV1, aV2);
gp_Pnt aPE1 = BRep_Tool::Pnt(aV1);
gp_Pnt aPE2 = BRep_Tool::Pnt(aV2);
if(aP1.IsEqual(aPE1, Precision::Confusion()) && aP2.IsEqual(aPE2, Precision::Confusion())) {
anArE.SetValue(i, anE);
aFound = Standard_True;
break;
}
}
if(!aFound)
anArE.SetValue(i, aShape);
else aFound = Standard_False;
}
if(isClosed) {
Standard_Boolean aFound = Standard_False;
gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(theArV.Value(aLength)));
gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(theArV.Value(1)));
TopExp_Explorer anExp(theWire,TopAbs_EDGE);
for(;anExp.More();anExp.Next()) {
const TopoDS_Edge& anE = TopoDS::Edge(anExp.Current());
TopoDS_Vertex aV, aV1, aV2;
TopExp::Vertices(anE, aV1, aV2);
gp_Pnt aPE1 = BRep_Tool::Pnt(aV1);
gp_Pnt aPE2 = BRep_Tool::Pnt(aV2);
if(aP1.IsEqual(aPE1, Precision::Confusion()) && aP2.IsEqual(aPE2, Precision::Confusion())) {
anArE.SetValue(aLength, anE);
aFound = Standard_True;
// closed case
aFirst = aV2;
aLast = aV1;
break;
}
}
if(!aFound)
anArE.SetValue(aLength, aShape);
} else {
// open
anArE.SetValue(aLength, aShape); // last edge
TopExp::Vertices(theWire, aFirst, aLast);
}
// put edges
// from 1:aLength - edges
for(Standard_Integer i1 = 1;i1 <= aLength ;i1++) {
TDF_Label aLab = theResultLabel.FindChild(i1);
if(!anArE.Value(i1).IsNull()) {
TNaming_Builder aBuilder(aLab);
aBuilder.Generated(anArE.Value(i1));
} else {
Handle(TNaming_NamedShape) aNS;
if(aLab.FindAttribute(TNaming_NamedShape::GetID(), aNS))
TNaming_Builder aB(aLab);
}
}
//put vertexes
// aLength +1 - first vertex
// aLength +2 - last vertex
TDF_Label aLab1 = theResultLabel.FindChild(aLength+1);
TDF_Label aLab2 = theResultLabel.FindChild(aLength+2);
if(!aFirst.IsNull()) {
TNaming_Builder aBuilder(aLab1);
aBuilder.Generated(aFirst);
} else {
Handle(TNaming_NamedShape) aNS;
if(aLab1.FindAttribute(TNaming_NamedShape::GetID(), aNS))
TNaming_Builder aB(aLab1);
}
if(!aLast.IsNull()) {
TNaming_Builder aBuilder(aLab2);
aBuilder.Generated(aLast);
} else {
Handle(TNaming_NamedShape) aNS;
if(aLab2.FindAttribute(TNaming_NamedShape::GetID(), aNS))
TNaming_Builder aB(aLab2);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,47 @@
-- File: DNaming_PointDriver.cdl
-- Created: Thu Feb 25 18:35:26 2010
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2010
class PointDriver from DNaming inherits Driver from TFunction
---Purpose: Driver for PointXYZ and RelativePoint
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction
is
Create returns mutable PointDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
end PointDriver;

View File

@@ -0,0 +1,114 @@
// File: DNaming_PointDriver.cxx
// Created: Thu Feb 25 18:49:04 2010
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2010
#include <DNaming_PointDriver.ixx>
//OCCT
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <gp_Pnt.hxx>
#include <Standard_GUID.hxx>
// OCAF
#include <TNaming.hxx>
#include <TDF_Label.hxx>
#include <TDataStd_Real.hxx>
#include <TFunction_Logbook.hxx>
#include <TFunction_Function.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Builder.hxx>
#include <DNaming.hxx>
#include <ModelDefinitions.hxx>
//=======================================================================
//function : DNaming_PointDriver
//purpose : Constructor
//=======================================================================
DNaming_PointDriver::DNaming_PointDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <log>.
//=======================================================================
void DNaming_PointDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <log> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_PointDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Execute the function and push in <log> the impacted labels
//=======================================================================
Standard_Integer DNaming_PointDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
// perform calculations
Standard_Real aDX = DNaming::GetReal(aFunction,PNT_DX)->Get();
Standard_Real aDY = DNaming::GetReal(aFunction,PNT_DY)->Get();
Standard_Real aDZ = DNaming::GetReal(aFunction,PNT_DZ)->Get();
Handle(TNaming_NamedShape) aPrevPnt = DNaming::GetFunctionResult(aFunction);
// Save location
TopLoc_Location aLocation;
if (!aPrevPnt.IsNull() && !aPrevPnt->IsEmpty()) {
aLocation = aPrevPnt->Get().Location();
}
gp_Pnt aPoint;
if(aFunction->GetDriverGUID() == PNTRLT_GUID) {
Handle(TDataStd_UAttribute) aRefPnt = DNaming::GetObjectArg(aFunction,PNTRLT_REF);
Handle(TNaming_NamedShape) aRefPntNS = DNaming::GetObjectValue(aRefPnt);
if (aRefPntNS.IsNull() || aRefPntNS->IsEmpty()) {
#ifdef DEB
cout<<"PointDriver:: Ref Point is empty"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
TopoDS_Shape aRefPntShape = aRefPntNS->Get();
TopoDS_Vertex aVertex = TopoDS::Vertex(aRefPntShape);
aPoint = BRep_Tool::Pnt(aVertex);
aPoint.SetX(aPoint.X()+aDX);
aPoint.SetY(aPoint.Y()+aDY);
aPoint.SetZ(aPoint.Z()+aDZ);
} else
aPoint = gp_Pnt(aDX, aDY, aDZ);
BRepBuilderAPI_MakeVertex aMakeVertex(aPoint);
if(!aMakeVertex.IsDone()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
// Naming
const TDF_Label& aResultLabel = RESPOSITION(aFunction);
TNaming_Builder aBuilder(aResultLabel);
aBuilder.Generated(aMakeVertex.Shape());
// restore location
if(!aLocation.IsIdentity())
TNaming::Displace(aResultLabel, aLocation, Standard_True);
theLog.SetValid(aResultLabel, Standard_True);
aFunction->SetFailure(DONE);
return 0;
}

View File

@@ -0,0 +1,54 @@
-- File: DNaming_PrismDriver.cdl
-- Created: Tue Jun 16 11:26:26 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class PrismDriver from DNaming inherits Driver from TFunction
---Purpose:
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
MakePrism from BRepPrimAPI,
Shape from TopoDS
is
Create returns mutable PrismDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; mkPrism : in out MakePrism from BRepPrimAPI;
Basis : Shape from TopoDS; Context : Shape from TopoDS)
is private;
end PrismDriver;

View File

@@ -0,0 +1,282 @@
// File: DNaming_PrismDriver.cxx
// Created: Tue Jun 16 11:38:30 2009
// Author: Sergey ZARITCHNY
// <szy@petrox.nnov.matra-dtv.fr>
#include <DNaming_PrismDriver.ixx>
// OCC
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <gp_Ax2.hxx>
#include <Geom_Line.hxx>
#include <BRep_Tool.hxx>
#include <BRepGProp.hxx>
#include <BRepCheck_Shell.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopLoc_Location.hxx>
#include <TopExp_Explorer.hxx>
#include <GProp_GProps.hxx>
#include <Precision.hxx>
#include <BRepCheck_Wire.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Solid.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Real.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
// OCAF
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TNaming.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TFunction_Function.hxx>
#include <TFunction_Logbook.hxx>
#include <TDF_Label.hxx>
#include <TDF_TagSource.hxx>
#include <DNaming.hxx>
#include <ModelDefinitions.hxx>
//=======================================================================
//function : DNaming_PrismDriver
//purpose : Constructor
//=======================================================================
DNaming_PrismDriver::DNaming_PrismDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <theLog>.
//=======================================================================
void DNaming_PrismDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyses in <theLog> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_PrismDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
#ifdef OCC_DEB
#include <BRepTools.hxx>
static void Write(const TopoDS_Shape& shape,
const Standard_CString filename)
{
ofstream save;
save.open(filename);
save << "DBRep_DrawableShape" << endl << endl;
if(!shape.IsNull()) BRepTools::Write(shape, save);
save.close();
}
#endif
//=======================================================================
//function : Execute
//purpose : Executes the function
//=======================================================================
Standard_Integer DNaming_PrismDriver::Execute(TFunction_Logbook& theLog) const {
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(), aFunction);
if(aFunction.IsNull()) return -1;
// Save location
Handle(TNaming_NamedShape) aPrevPrism = DNaming::GetFunctionResult(aFunction);
TopLoc_Location aLocation;
if (!aPrevPrism.IsNull() && !aPrevPrism->IsEmpty()) {
aLocation = aPrevPrism->Get().Location();
}
//Basis for IPrism
Handle(TDataStd_UAttribute) aBasObject = DNaming::GetObjectArg(aFunction,PRISM_BASIS);
Handle(TNaming_NamedShape) aBasisNS = DNaming::GetObjectValue(aBasObject);
if(aBasisNS.IsNull() || aBasisNS->IsEmpty()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
const TopoDS_Shape& aBasis = aBasisNS->Get();
TopoDS_Shape aBASIS;
if(aBasis.ShapeType() == TopAbs_WIRE) {
Handle(BRepCheck_Wire) aCheck = new BRepCheck_Wire(TopoDS::Wire(aBasis));
if(aCheck->Closed(Standard_True) == BRepCheck_NoError) {
BRepBuilderAPI_MakeFace aMaker (TopoDS::Wire(aBasis), Standard_True); //Makes planar face
if(aMaker.IsDone())
aBASIS = aMaker.Face();//aMaker.Face();
}
} else if(aBasis.ShapeType() == TopAbs_FACE)
aBASIS = aBasis;
if(aBASIS.IsNull()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
Handle(TNaming_NamedShape) aContextOfBasis;
Standard_Boolean anIsAttachment = Standard_False;
if(DNaming::IsAttachment(aBasObject)) {
aContextOfBasis = DNaming::GetAttachmentsContext(aBasObject); // a Context of Prism basis
if(aContextOfBasis.IsNull() || aContextOfBasis->IsEmpty()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
anIsAttachment = Standard_True;
}
// Height
Standard_Real aHeight = DNaming::GetReal(aFunction,PRISM_HEIGHT)->Get();
if(aHeight <= Precision::Confusion()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
// Direction
gp_Ax1 anAxis;
DNaming::ComputeSweepDir(aBasis, anAxis);
// Reverse
Standard_Integer aRev = DNaming::GetInteger(aFunction,PRISM_DIR)->Get();
if(aRev) anAxis.Reverse();
// Calculate Vec - direction of extrusion
gp_Vec aVEC(anAxis.Direction());
aVEC = aVEC*aHeight;
BRepPrimAPI_MakePrism aMakePrism(aBASIS, aVEC, Standard_True);
aMakePrism.Build();
if (!aMakePrism.IsDone()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
const TopoDS_Shape& aResult = aMakePrism.Shape();
BRepCheck_Analyzer aCheck(aResult);
if (!aCheck.IsValid(aResult)) {
aFunction->SetFailure(RESULT_NOT_VALID);
#ifdef OCC_DEB
Standard_CString aFileName = "PrismResult.brep";
Write(aResult, aFileName);
#endif
return -1;
}
Standard_Boolean aVol = Standard_False;
if(aResult.ShapeType() == TopAbs_SOLID) aVol = Standard_True;
else if(aResult.ShapeType() == TopAbs_SHELL) {
Handle(BRepCheck_Shell) aCheck = new BRepCheck_Shell(TopoDS::Shell(aResult));
if(aCheck->Closed() == BRepCheck_NoError)
aVol = Standard_True;
}
if(aVol) {
GProp_GProps aGProp;
BRepGProp::VolumeProperties(aResult, aGProp);
if(aGProp.Mass() <= Precision::Confusion()) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
}
// Naming
if(anIsAttachment)
LoadNamingDS(RESPOSITION(aFunction), aMakePrism, aBASIS, aContextOfBasis->Get());
else
LoadNamingDS(RESPOSITION(aFunction), aMakePrism, aBASIS, aBASIS);
// restore location
if(!aLocation.IsIdentity())
TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
theLog.SetValid(RESPOSITION(aFunction),Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=======================================================================
//function : LoadAndName
//purpose :
//=======================================================================
void DNaming_PrismDriver::LoadNamingDS (const TDF_Label& theResultLabel,
BRepPrimAPI_MakePrism& MS,
const TopoDS_Shape& Basis,
const TopoDS_Shape& Context
) const
{
TopTools_DataMapOfShapeShape SubShapes;
for (TopExp_Explorer Exp(MS.Shape(),TopAbs_FACE); Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(theResultLabel);
if (Tagger.IsNull()) return;
Tagger->Set(0);
TNaming_Builder Builder (theResultLabel);
if(Basis.IsEqual(Context))
Builder.Generated(MS.Shape());
else
Builder.Generated(Context, MS.Shape());
//Insert lateral face : Face from Edge
TNaming_Builder LateralFaceBuilder(theResultLabel.NewChild());
DNaming::LoadAndOrientGeneratedShapes(MS, Basis, TopAbs_EDGE, LateralFaceBuilder, SubShapes);
Standard_Boolean makeTopBottom = Standard_True;
if (Basis.ShapeType() == TopAbs_COMPOUND) {
TopoDS_Iterator itr(Basis);
if (itr.More() && itr.Value().ShapeType() == TopAbs_WIRE) makeTopBottom = Standard_False;
} else if (Basis.ShapeType() == TopAbs_WIRE) {
makeTopBottom = Standard_False;
}
if (makeTopBottom) {
//Insert bottom face
TopoDS_Shape BottomFace = MS.FirstShape();
if (!BottomFace.IsNull()) {
if (BottomFace.ShapeType() != TopAbs_COMPOUND) {
TNaming_Builder BottomBuilder(theResultLabel.NewChild()); //2
if (SubShapes.IsBound(BottomFace)) {
BottomFace = SubShapes(BottomFace);
}
BottomBuilder.Generated(BottomFace);
} else {
TopoDS_Iterator itr(BottomFace);
for (; itr.More(); itr.Next()) {
TNaming_Builder BottomBuilder(theResultLabel.NewChild());
BottomBuilder.Generated(itr.Value());
}
}
}
//Insert top face
TopoDS_Shape TopFace = MS.LastShape();
if (!TopFace.IsNull()) {
if (TopFace.ShapeType() != TopAbs_COMPOUND) {
TNaming_Builder TopBuilder(theResultLabel.NewChild()); //3
if (SubShapes.IsBound(TopFace)) {
TopFace = SubShapes(TopFace);
}
TopBuilder.Generated(TopFace);
} else {
TopoDS_Iterator itr(TopFace);
for (; itr.More(); itr.Next()) {
TNaming_Builder TopBuilder(theResultLabel.NewChild());
TopBuilder.Generated(itr.Value());
}
}
}
}
}

View File

@@ -0,0 +1,53 @@
-- File: DNaming_RevolutionDriver.cdl
-- Created: Wed Jun 17 15:34:53 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class RevolutionDriver from DNaming inherits Driver from TFunction
---Purpose:
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
MakeRevol from BRepPrimAPI,
Shape from TopoDS
is
Create returns mutable RevolutionDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; mkRevol : in out MakeRevol from BRepPrimAPI;
Basis : Shape from TopoDS; Context : Shape from TopoDS)
is private;
end RevolutionDriver;

View File

@@ -0,0 +1,541 @@
// File: DNaming_RevolutionDriver.cxx
// Created: Wed Jun 17 15:37:42 2009
// Author: Sergey ZARITCHNY
// <szy@petrox.nnov.matra-dtv.fr>
#include <DNaming_RevolutionDriver.ixx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <gp_Ax2.hxx>
#include <Geom_Line.hxx>
#include <BRep_Tool.hxx>
#include <BRepGProp.hxx>
#include <BRepCheck_Shell.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <BRepPrimAPI_MakeRevol.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopLoc_Location.hxx>
#include <TopExp_Explorer.hxx>
#include <GProp_GProps.hxx>
#include <Precision.hxx>
#include <BRepCheck_Wire.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Solid.hxx>
#include <Standard_GUID.hxx>
#include <Standard_Real.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopExp.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
// OCAF
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TNaming.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TFunction_Function.hxx>
#include <TFunction_Logbook.hxx>
#include <TDF_Label.hxx>
#include <TDF_TagSource.hxx>
#include <DNaming.hxx>
#include <ModelDefinitions.hxx>
//=======================================================================
//function : DNaming_RevolutionDriver
//purpose : Constructor
//=======================================================================
DNaming_RevolutionDriver::DNaming_RevolutionDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <theLog>.
//=======================================================================
void DNaming_RevolutionDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyses in <theLog> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_RevolutionDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
#ifdef OCC_DEB
#include <BRepTools.hxx>
static void Write(const TopoDS_Shape& shape,
const Standard_CString filename)
{
ofstream save;
save.open(filename);
save << "DBRep_DrawableShape" << endl << endl;
if(!shape.IsNull()) BRepTools::Write(shape, save);
save.close();
}
#endif
//=======================================================================
//function : Execute
//purpose : Executes the function
//=======================================================================
Standard_Integer DNaming_RevolutionDriver::Execute(TFunction_Logbook& theLog) const {
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(), aFunction);
if(aFunction.IsNull()) return -1;
// Save location
Handle(TNaming_NamedShape) aPrevRevol = DNaming::GetFunctionResult(aFunction);
TopLoc_Location aLocation;
if (!aPrevRevol.IsNull() && !aPrevRevol->IsEmpty()) {
aLocation = aPrevRevol->Get().Location();
}
//Basis for Revol
Handle(TDataStd_UAttribute) aBasObject = DNaming::GetObjectArg(aFunction,REVOL_BASIS);
Handle(TNaming_NamedShape) aBasisNS = DNaming::GetObjectValue(aBasObject);
if(aBasisNS.IsNull() || aBasisNS->IsEmpty()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
const TopoDS_Shape& aBasis = aBasisNS->Get();
TopoDS_Shape aBASIS;
if(aBasis.ShapeType() == TopAbs_WIRE) {
Handle(BRepCheck_Wire) aCheck = new BRepCheck_Wire(TopoDS::Wire(aBasis));
if(aCheck->Closed(Standard_True) == BRepCheck_NoError) {
BRepBuilderAPI_MakeFace aMaker (TopoDS::Wire(aBasis), Standard_True); //Makes planar face
if(aMaker.IsDone())
aBASIS = aMaker.Face();//aMaker.Face();
}
} else if(aBasis.ShapeType() == TopAbs_FACE)
aBASIS = aBasis;
if(aBASIS.IsNull()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
Handle(TNaming_NamedShape) aContextOfBasis;
Standard_Boolean anIsAttachment = Standard_False;
if(DNaming::IsAttachment(aBasObject)) {
aContextOfBasis = DNaming::GetAttachmentsContext(aBasObject); // a Context of Revolution basis
if(aContextOfBasis.IsNull() || aContextOfBasis->IsEmpty()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
anIsAttachment = Standard_True;
}
// Axis
Handle(TDataStd_UAttribute) anAxObject = DNaming::GetObjectArg(aFunction,REVOL_AXIS);
Handle(TNaming_NamedShape) anAxNS = DNaming::GetObjectValue(anAxObject);
gp_Ax1 anAXIS;
TopoDS_Shape aTopoDSAxis;
if(anAxNS.IsNull() || anAxNS->IsEmpty()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
} else {
aTopoDSAxis = anAxNS->Get();
Standard_Boolean anAxisOK = Standard_False;
if (!aTopoDSAxis.IsNull()) {
if(aTopoDSAxis.ShapeType() == TopAbs_EDGE || aTopoDSAxis.ShapeType() == TopAbs_WIRE) {
if (aTopoDSAxis.ShapeType() == TopAbs_WIRE) {
TopExp_Explorer anExplorer(aTopoDSAxis, TopAbs_EDGE);
aTopoDSAxis = anExplorer.Current();
}
const TopoDS_Edge& anEdge = TopoDS::Edge(aTopoDSAxis);
Standard_Real aFirst, aLast;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge,aFirst,aLast) ;
if (aCurve->IsKind (STANDARD_TYPE(Geom_Line)) ) {
Handle(Geom_Line) aLine = Handle(Geom_Line)::DownCast(aCurve) ;
if(!aLine.IsNull()) {
anAXIS = aLine->Position() ;
anAxisOK = Standard_True;
}
}
}
}
if(!anAxisOK) {
#ifdef OCC_DEB
cout<<"RevolutionDriver:: Axis is not correct"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
}
if(aFunction->GetDriverGUID() == FULREVOL_GUID) {
BRepPrimAPI_MakeRevol aMakeRevol(aBASIS, anAXIS, Standard_True);
aMakeRevol.Build();
if (!aMakeRevol.IsDone()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
const TopoDS_Shape aResult = aMakeRevol.Shape();
BRepCheck_Analyzer aCheck(aResult);
if (!aCheck.IsValid(aResult)) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
Standard_Boolean aVol = Standard_False;
if(aResult.ShapeType() == TopAbs_SOLID) aVol = Standard_True;
else if(aResult.ShapeType() == TopAbs_SHELL) {
Handle(BRepCheck_Shell) aCheck = new BRepCheck_Shell(TopoDS::Shell(aResult));
if(aCheck->Closed() == BRepCheck_NoError)
aVol = Standard_True;
}
if(aVol) {
GProp_GProps aGProp;
BRepGProp::VolumeProperties(aResult, aGProp);
if(aGProp.Mass() <= Precision::Confusion()) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
}
// Naming
if(anIsAttachment)
LoadNamingDS(RESPOSITION(aFunction), aMakeRevol, aBASIS, aContextOfBasis->Get());
else
LoadNamingDS(RESPOSITION(aFunction), aMakeRevol, aBASIS, aBASIS);
} else if(aFunction->GetDriverGUID() == SECREVOL_GUID) {
Standard_Real anANGLE = DNaming::GetReal(aFunction,REVOL_ANGLE)->Get();
if(anANGLE <= Precision::Confusion()) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
// Reverse
Standard_Integer aRev = DNaming::GetInteger(aFunction,REVOL_REV)->Get();
if(aRev) anAXIS.Reverse();
BRepPrimAPI_MakeRevol aMakeRevol(aBASIS, anAXIS, anANGLE, Standard_True);
aMakeRevol.Build();
if (!aMakeRevol.IsDone()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
const TopoDS_Shape aResult = aMakeRevol.Shape();
BRepCheck_Analyzer aCheck(aResult);
if (!aCheck.IsValid(aResult)) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
Standard_Boolean aVol = Standard_False;
if(aResult.ShapeType() == TopAbs_SOLID) aVol = Standard_True;
else if(aResult.ShapeType() == TopAbs_SHELL) {
Handle(BRepCheck_Shell) aCheck = new BRepCheck_Shell(TopoDS::Shell(aResult));
if(aCheck->Closed() == BRepCheck_NoError)
aVol = Standard_True;
}
if(aVol) {
GProp_GProps aGProp;
BRepGProp::VolumeProperties(aResult, aGProp);
if(aGProp.Mass() <= Precision::Confusion()) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
}
// Naming
if(anIsAttachment)
LoadNamingDS(RESPOSITION(aFunction), aMakeRevol, aBASIS, aContextOfBasis->Get());
else
LoadNamingDS(RESPOSITION(aFunction), aMakeRevol, aBASIS, aBASIS);
} else {
aFunction->SetFailure(UNSUPPORTED_FUNCTION);
return -1;
}
// restore location
if(!aLocation.IsIdentity())
TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
theLog.SetValid(RESPOSITION(aFunction),Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=======================================================================
static void LoadSeamEdge (BRepPrimAPI_MakeRevol& mkRevol,
const TDF_Label& ResultLabel,
const TopoDS_Shape& ShapeIn)
{
TopTools_MapOfShape View;
TopExp_Explorer ShapeExplorer (ShapeIn, TopAbs_EDGE);
Standard_Boolean isFound(Standard_False);
for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
const TopoDS_Shape& Root = ShapeExplorer.Current ();
if (!View.Add(Root)) continue;
const TopTools_ListOfShape& Shapes = mkRevol.Generated (Root);
TopTools_ListIteratorOfListOfShape ShapesIterator (Shapes);
for (;ShapesIterator.More (); ShapesIterator.Next ()) {
TopoDS_Shape newShape = ShapesIterator.Value ();
if(newShape.ShapeType() != TopAbs_FACE)
continue;
if (!Root.IsSame (newShape)) {
TopExp_Explorer exp(newShape, TopAbs_EDGE);
for (;exp.More();exp.Next()) {
if(BRep_Tool::IsClosed (TopoDS::Edge(exp.Current()), TopoDS::Face(newShape))) {
TNaming_Builder Builder(ResultLabel.NewChild());
Builder.Generated (exp.Current());
isFound = Standard_True;
break;
}
}
if(isFound) {isFound = Standard_False;break;}
}
}
}
}
//=======================================================================
static Standard_Boolean HasDangle(const TopoDS_Shape& ShapeIn)
{
if (ShapeIn.ShapeType() == TopAbs_SOLID)
return Standard_False;
else if (ShapeIn.ShapeType() == TopAbs_SHELL) {
Handle(BRepCheck_Shell) aCheck = new BRepCheck_Shell(TopoDS::Shell(ShapeIn));
if(aCheck->Closed() == BRepCheck_NoError)
return Standard_False;
else
Standard_True;
} else if (ShapeIn.ShapeType() == TopAbs_FACE ||
ShapeIn.ShapeType() == TopAbs_WIRE ||
ShapeIn.ShapeType() == TopAbs_EDGE ||
ShapeIn.ShapeType() == TopAbs_VERTEX)
return Standard_True;
return Standard_False;
}
//=======================================================================
static void BuildAtomicMap(const TopoDS_Shape& S, TopTools_MapOfShape& M)
{
if(S.ShapeType() == TopAbs_COMPOUND || S.ShapeType() == TopAbs_COMPSOLID) {
TopoDS_Iterator it(S);
for(;it.More();it.Next()) {
if(it.Value().ShapeType() > TopAbs_COMPSOLID)
M.Add(it.Value());
else
BuildAtomicMap(it.Value(), M);
}
} else
M.Add(S);
}
//=======================================================================
//function : HasDangleShapes
//purpose :
//=======================================================================
Standard_Boolean HasDangleShapes(const TopoDS_Shape& ShapeIn) {
if (ShapeIn.ShapeType() == TopAbs_COMPOUND || ShapeIn.ShapeType() == TopAbs_COMPSOLID) {
TopTools_MapOfShape M;
BuildAtomicMap(ShapeIn, M);
TopTools_MapIteratorOfMapOfShape it(M);
for (; it.More(); it.Next())
if (HasDangle(it.Key())) return Standard_True;
} else
return HasDangle(ShapeIn);
return Standard_False;
}
//=======================================================================
//function : LoadAndName
//purpose :
//=======================================================================
void DNaming_RevolutionDriver::LoadNamingDS (const TDF_Label& theResultLabel,
BRepPrimAPI_MakeRevol& MS,
const TopoDS_Shape& Basis,
const TopoDS_Shape& Context
) const
{
TopTools_DataMapOfShapeShape SubShapes;
for (TopExp_Explorer Exp(MS.Shape(),TopAbs_FACE); Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(theResultLabel);
if (Tagger.IsNull()) return;
Tagger->Set(0);
TNaming_Builder Builder (theResultLabel);
if(Basis.IsEqual(Context))
Builder.Generated(MS.Shape());
else
Builder.Generated(Context, MS.Shape());
//Insert lateral face : Face from Edge
TNaming_Builder LateralFaceBuilder(theResultLabel.NewChild());
DNaming::LoadAndOrientGeneratedShapes(MS, Basis, TopAbs_EDGE, LateralFaceBuilder, SubShapes);
// is full
TopoDS_Shape StartShape = MS.FirstShape();
TopoDS_Shape EndShape = MS.LastShape();
Standard_Boolean isFull(Standard_False);
if (!StartShape.IsNull() && !EndShape.IsNull())
isFull = StartShape.IsEqual(EndShape);
Standard_Boolean hasDangle = HasDangleShapes(MS.Shape());
Standard_Boolean isBasisClosed(Standard_True);
TopoDS_Vertex Vfirst, Vlast;
if(Basis.ShapeType() == TopAbs_WIRE) {
Handle(BRepCheck_Wire) aCheck = new BRepCheck_Wire(TopoDS::Wire(Basis));
if(aCheck->Closed() != BRepCheck_NoError) {
isBasisClosed = Standard_False; //open
TopExp::Vertices(TopoDS::Wire(Basis), Vfirst, Vlast);
}
} else if(Basis.ShapeType() == TopAbs_EDGE) {
BRepBuilderAPI_MakeWire aMakeWire;
aMakeWire.Add(TopoDS::Edge(Basis));
if(aMakeWire.IsDone()) {
Handle(BRepCheck_Wire) aCheck = new BRepCheck_Wire(aMakeWire.Wire());
if(aCheck->Closed() != BRepCheck_NoError) {//check for circle case
isBasisClosed = Standard_False; //open
TopExp::Vertices(TopoDS::Edge(Basis), Vfirst, Vlast);
}
}
}
if(isFull) {
//seam edge
LoadSeamEdge(MS, theResultLabel, Basis);
if(hasDangle) {
if(!isBasisClosed) {
//dangle edges
const TopTools_ListOfShape& Shapes = MS.Generated (Vfirst);
TopTools_ListIteratorOfListOfShape it (Shapes);
for (;it.More (); it.Next ()) {
if(!BRep_Tool::Degenerated(TopoDS::Edge(it.Value()))) {
TNaming_Builder aBuilder(theResultLabel.NewChild());
aBuilder.Generated (Vfirst, it.Value());
}
#ifdef OCC_DEB
else {
if(MS.HasDegenerated())
cout <<"mkRevol has degenerated" <<endl;
cout << "BRep_Tool found degenerated edge (from Vfirst) TS = " << it.Value().TShape() <<endl;
}
#endif
}
const TopTools_ListOfShape& Shapes2 = MS.Generated (Vlast);
it.Initialize(Shapes2);
for (;it.More (); it.Next ()) {
if(!BRep_Tool::Degenerated(TopoDS::Edge(it.Value()))) {
TNaming_Builder aBuilder(theResultLabel.NewChild());
aBuilder.Generated (Vlast, it.Value());
}
#ifdef OCC_DEB
else {
if(MS.HasDegenerated())
cout <<"mkRevol has degenerated" <<endl;
cout << "BRep_Tool found degenerated edge (from Vlast) TS = " << it.Value().TShape() <<endl;
}
#endif
}
}
}
} else {//if(!isFull)
//Insert start shape
if (!StartShape.IsNull()) {
if (StartShape.ShapeType() != TopAbs_COMPOUND) {
TNaming_Builder StartBuilder(theResultLabel.NewChild());
if (SubShapes.IsBound(StartShape)) {
StartShape = SubShapes(StartShape);
}
StartBuilder.Generated(StartShape);
if(StartShape.ShapeType() != TopAbs_FACE) {
TopoDS_Iterator it(StartShape);
for (; it.More(); it.Next()) {
TNaming_Builder Builder(theResultLabel.NewChild());
Builder.Generated(it.Value());
}
}
} else {
TopoDS_Iterator itr(StartShape);
for (; itr.More(); itr.Next()) {
TNaming_Builder StartBuilder(theResultLabel.NewChild());
StartBuilder.Generated(itr.Value());
}
}
}
//Insert end shape
if (!EndShape.IsNull()) {
if (EndShape.ShapeType() != TopAbs_COMPOUND) {
TNaming_Builder EndBuilder(theResultLabel.NewChild());
if (SubShapes.IsBound(EndShape)) {
EndShape = SubShapes(EndShape);
}
EndBuilder.Generated(EndShape);
if(EndShape.ShapeType() != TopAbs_FACE) {
TopoDS_Iterator it(EndShape);
for (; it.More(); it.Next()) {
TNaming_Builder Builder(theResultLabel.NewChild());
Builder.Generated(it.Value());
}
}
} else {
TopoDS_Iterator itr(EndShape);
for (; itr.More(); itr.Next()) {
TNaming_Builder EndBuilder(theResultLabel.NewChild());
EndBuilder.Generated(itr.Value());
}
}
}
if(hasDangle) {
if(!isBasisClosed) {
//dangle edges
const TopTools_ListOfShape& Shapes = MS.Generated (Vfirst);
TopTools_ListIteratorOfListOfShape it (Shapes);
for (;it.More (); it.Next ()) {
if(!BRep_Tool::Degenerated(TopoDS::Edge(it.Value()))) {
TNaming_Builder aBuilder(theResultLabel.NewChild());
aBuilder.Generated (Vfirst, it.Value());
}
#ifdef OCC_DEB
else {
if(MS.HasDegenerated())
cout <<"mkRevol has degenerated" <<endl;
cout << "BRep_Tool found degenerated edge (from Vfirst) TS = " << it.Value().TShape() <<endl;
}
#endif
}
const TopTools_ListOfShape& Shapes2 = MS.Generated (Vlast);
it.Initialize(Shapes2);
for (;it.More (); it.Next ()) {
if(!BRep_Tool::Degenerated(TopoDS::Edge(it.Value()))) {
TNaming_Builder aBuilder(theResultLabel.NewChild());
aBuilder.Generated (Vlast, it.Value());
}
#ifdef OCC_DEB
else {
if(MS.HasDegenerated())
cout <<"mkRevol has degenerated" <<endl;
cout << "BRep_Tool found degenerated edge (from Vlast) TS = " << it.Value().TShape() <<endl;
}
#endif
}
}
}
}
}

View File

@@ -0,0 +1,52 @@
proc SelectLoop { DF shape T} {
#
# loop to select all the sub-shapes of type <T> in the context <shape>
#
global $DF
global $shape
display $shape
fit
clear
set L [Label $DF 0:1000]
isos $shape 0
set ter _*
global $ter
foreach S [directory [concat $shape$ter]] {
global $S
unset $S
}
uplevel #0 explode $shape $T
foreach S [directory [concat $shape$ter]] {
clear
puts $S
global $S
display $shape
display $S
#wclick
#SelectShape $DF $L $S $shape
SelectGeometry $DF $L $S $shape
DumpSelection $DF $L 1
wclick
SolveSelection $DF $L
pick ID x y z b
if {[dval b] == 3} {
foreach OS [directory [concat $shape$ter]] {
global $OS
unqset $OS
}
return
}
}
}

View File

@@ -0,0 +1,346 @@
// File: DDesignPart_SelectionCommands.cxx
// Created: Mon Oct 20 16:18:02 1997
// Author: Yves FRICAUD
// <yfr@claquox.paris1.matra-dtv.fr>
#include <DNaming.hxx>
#include <DDF.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_ListOfNamedShape.hxx>
#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
#include <TNaming_Tool.hxx>
#include <TDF_Label.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_Tool.hxx>
#include <TNaming_Name.hxx>
#include <TNaming.hxx>
#include <TNaming_Naming.hxx>
#include <TNaming_MapOfNamedShape.hxx>
#include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
#include <TDF_ChildIterator.hxx>
#include <TNaming_Selector.hxx>
#include <TopoDS_Shape.hxx>
#include <TopAbs.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_LabelMap.hxx>
#include <DBRep.hxx>
#include <Draw_Appli.hxx>
#include <Draw.hxx>
#include <Draw_Interpretor.hxx>
#include <Draw_Drawable3D.hxx>
#include <DBRep.hxx>
#include <DBRep_DrawableShape.hxx>
#include <stdio.h>
//=======================================================================
//function : Display
//purpose :
//=======================================================================
static void Display (const Standard_CString Name, const TopoDS_Shape& S)
{
//char* name = Name;
static Standard_Integer nbIsos = 2;
static Standard_Real size = 100.;
static Standard_Integer discret = 30;
Handle(DBRep_DrawableShape) D = new DBRep_DrawableShape(S,
Draw_jaune,
Draw_vert,
Draw_bleu,
Draw_rouge,
size,
nbIsos,
discret);
Draw::Set(Name,D);
}
//=======================================================================
//function : DumpNaming
//purpose :
//=======================================================================
//static void DumpNaming (const Handle(TNaming_Naming)& naming)
static void DumpNaming (const Handle(TNaming_Naming)& naming, Draw_Interpretor& di)
{
TCollection_AsciiString Entry;
const TNaming_Name& AName = naming->GetName();
//TNaming::Print(AName.Type(),cout);
Standard_SStream aStream1;
TNaming::Print(AName.Type(),aStream1);
di << aStream1;
di << " ";
//TopAbs::Print(AName.ShapeType(),cout);
Standard_SStream aStream2;
TopAbs::Print(AName.ShapeType(),aStream2);
di << aStream2;
const TNaming_ListOfNamedShape& NSS = AName.Arguments();
for (TNaming_ListIteratorOfListOfNamedShape it(NSS); it.More(); it.Next()) {
TDF_Tool::Entry(it.Value()->Label(),Entry);
di << " " << Entry.ToCString();
}
if(!AName.StopNamedShape().IsNull()) {
TDF_Tool::Entry(AName.StopNamedShape()->Label(),Entry);
di << " Stop " << Entry.ToCString();
}
}
//=======================================================================
//function : SelectShape ou SelectGeometry
//purpose : "Select DF entry shape [context [orient]]",
//=======================================================================
static Standard_Integer DNaming_Select (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n > 3) {
Standard_Boolean geometry = (strcmp(a[0],"SelectGeometry"));
Handle(TDF_Data) DF;
if(!DDF::GetDF(a[1], DF)) return 1;
TDF_Label L;
DDF::AddLabel(DF,a[2],L);
TNaming_Selector SL (L);
if (n == 4) {
TopoDS_Shape S = DBRep::Get(a[3], TopAbs_SHAPE);
SL.Select (S, geometry);
}
if (n > 4) {
Standard_Boolean Orient(Standard_False);
if(n == 6) Orient = (Standard_Boolean)atoi(a[5]);
TopoDS_Shape S = DBRep::Get(a[3], TopAbs_SHAPE);
TopoDS_Shape C = DBRep::Get(a[4], TopAbs_SHAPE);
SL.Select (S, C, geometry, Orient);
}
return 0;
}
di << "DNaming_Select : Error" << "\n";
return 1;
}
//=======================================================================
//function : SolveSelection
//purpose : "SolveSelection DF entry",
//=======================================================================
static Standard_Integer DNaming_SolveSelection (Draw_Interpretor& di, Standard_Integer n, const char** a)
{
if (n == 3) {
char name[100];
Handle(TDF_Data) DF;
if(!DDF::GetDF(a[1], DF)) return 1;
TDF_Label L;
DDF::AddLabel(DF,a[2],L);
//Handle(TNaming_Naming) naming;
//if (!L.FindAttribute(TNaming_Naming::GetID(),naming)) {
// cout <<"DNaming_DumpSelection : not a selection" << endl;
// return 1;
//}
//naming->Solve();
//Handle(TNaming_NamedShape) NS;
//if (!L.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
// cout <<"DNaming_DumpSelection : not done" << endl;
// return 1;
//}
TNaming_Selector SL (L);
TDF_LabelMap dummy;
SL.Solve(dummy);
TopoDS_Shape Res = TNaming_Tool::CurrentShape(SL.NamedShape());
//TopoDS_Shape Res = TNaming_Tool::CurrentShape(NS);
sprintf (name,"%s_%s","new",a[2]);
Display (name,Res);
return 0;
}
di << "DNaming_SolveSelection : Error" << "\n";
return 1;
}
//=======================================================================
//function : DumpSelection
//purpose : DumpSelection DF entry (R)"
//=======================================================================
static Standard_Integer DNaming_DumpSelection (Draw_Interpretor& di,
Standard_Integer n, const char** a)
{
if (n == 3 || n == 4) {
Handle(TDF_Data) DF;
if (!DDF::GetDF(a[1],DF)) return 1;
TDF_Label L;
if (!DDF::FindLabel(DF,a[2],L)) return 1;
Handle(TNaming_Naming) naming;
if (!L.FindAttribute(TNaming_Naming::GetID(),naming)) {
di <<"DNaming_DumpSelection : not a selection" << "\n";
return 1;
}
DumpNaming(naming, di);
di << "\n";
if (n == 4) {
Standard_Integer depth = L.Depth();
Standard_Integer curdepth = 0;
TCollection_AsciiString Entry;
TDF_ChildIterator it (naming->Label(),Standard_True);
for (;it.More();it.Next()) {
if (it.Value().FindAttribute(TNaming_Naming::GetID(),naming)) {
curdepth = (naming->Label().Depth()- depth);
for (Standard_Integer i = 1; i <= curdepth; i++) di << " ";
TDF_Tool::Entry (naming->Label(),Entry);
di << Entry.ToCString() << " ";
DumpNaming(naming, di);
di << "\n";
}
}
}
return 0;
}
di << "DNaming_DumpSelection : Error" << "\n";
return 1;
}
//=======================================================================
//function : ArgsSelection
//purpose : ArgsSelection DF entry"
//=======================================================================
static Standard_Integer DNaming_ArgsSelection (Draw_Interpretor& di,
Standard_Integer n, const char** a)
{
if (n == 3) {
Handle(TDF_Data) DF;
if (!DDF::GetDF(a[1],DF)) return 1;
TDF_Label L;
if (!DDF::FindLabel(DF,a[2],L)) return 1;
Handle(TNaming_Naming) naming;
if (!L.FindAttribute(TNaming_Naming::GetID(),naming)) {
di <<"DNaming_DumpSelection : not a selection" << "\n";
return 1;
}
TCollection_AsciiString Entry;
TNaming_Selector SL (L);
di <<" Selection Arguments : ";
TDF_AttributeMap args;
SL.Arguments(args);
for (TDF_MapIteratorOfAttributeMap it(args); it.More(); it.Next()) {
TDF_Tool::Entry(it.Key()->Label(),Entry);
di << Entry.ToCString() << " ";
}
di << "\n";
return 0;
}
di << "DNaming_ArgsSelection : Error" << "\n";
return 1;
}
//=======================================================================
//function : CollectAttachment
//purpose :
//=======================================================================
static void CollectAttachment (const TDF_Label& root,
const Handle(TNaming_Naming)& naming,
TNaming_MapOfNamedShape& attachment)
{
TNaming_ListIteratorOfListOfNamedShape itarg;
const TNaming_ListOfNamedShape& args = naming->GetName().Arguments();
for (itarg.Initialize(args);itarg.More();itarg.Next()) {
if (!itarg.Value()->Label().IsDescendant(root)) attachment.Add(itarg.Value());
}
Handle(TNaming_Naming) subnaming;
for (TDF_ChildIterator it(naming->Label(),Standard_True);it.More();it.Next()) {
if (it.Value().FindAttribute(TNaming_Naming::GetID(),subnaming)) {
const TNaming_ListOfNamedShape& subargs = subnaming->GetName().Arguments();
for (itarg.Initialize(subargs);itarg.More();itarg.Next()) {
if (!itarg.Value()->Label().IsDescendant(root)) attachment.Add(itarg.Value());
}
}
}
}
//=======================================================================
//function : Attachment
//purpose : Attachment DF entry"
//=======================================================================
static Standard_Integer DNaming_Attachment (Draw_Interpretor& di,
Standard_Integer n,
const char** a)
{
if (n == 3) {
Handle(TDF_Data) DF;
if (!DDF::GetDF(a[1],DF)) return 1;
TDF_Label L;
if (!DDF::FindLabel(DF,a[2],L)) return 1;
Handle(TNaming_Naming) naming;
TNaming_MapOfNamedShape attachment;
if (L.FindAttribute(TNaming_Naming::GetID(),naming)) {
CollectAttachment (L,naming,attachment);
}
else {
for (TDF_ChildIterator it (L,Standard_True); it.More();it.Next()) {
if (it.Value().FindAttribute(TNaming_Naming::GetID(),naming)) {
CollectAttachment (L,naming,attachment);
it.NextBrother();
}
}
}
TCollection_AsciiString Entry;
TDF_Tool::Entry(L,Entry);
di << " Attachment of " << Entry.ToCString();
di << "\n";
for (TNaming_MapIteratorOfMapOfNamedShape ita (attachment); ita.More(); ita.Next()) {
TDF_Tool::Entry (ita.Key()->Label(),Entry);
di << Entry.ToCString() << " ";
}
di << "\n";
return 0;
}
di << "DNaming_Attachment : Error" << "\n";
return 1;
}
//=======================================================================
//function : SelectionCommands
//purpose :
//=======================================================================
void DNaming::SelectionCommands(Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
done = Standard_True;
const char* g = "Naming data commands";
theCommands.Add("SelectShape",
"SelectShape DF entry shape [context [Orient]]",
__FILE__, DNaming_Select, g);
theCommands.Add("SelectGeometry",
"SelectGeometry DF entry shape [context]",
__FILE__, DNaming_Select, g);
theCommands.Add("DumpSelection",
"DumpSelected DF entry",
__FILE__, DNaming_DumpSelection, g);
theCommands.Add("ArgsSelection",
"ArgsSelection DF entry",
__FILE__, DNaming_ArgsSelection, g);
theCommands.Add("SolveSelection",
"DumpSelection DF entry",
__FILE__, DNaming_SolveSelection, g);
theCommands.Add("Attachment",
"Attachment DF entry",
__FILE__, DNaming_Attachment, g);
}

View File

@@ -0,0 +1,48 @@
-- File: DNaming_SelectionDriver.cdl
-- Created: Tue May 5 10:29:43 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class SelectionDriver from DNaming inherits Driver from TFunction
---Purpose:
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection
is
Create returns mutable SelectionDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
end SelectionDriver;

View File

@@ -0,0 +1,174 @@
// File: DNaming_SelectionDriver.cxx
// Created: Tue May 5 10:42:07 2009
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2009
#include <DNaming_SelectionDriver.ixx>
#include <TopAbs.hxx>
#include <TopoDS_Shape.hxx>
#include <TDF_Label.hxx>
#include <TDF_LabelMap.hxx>
#include <TFunction_Logbook.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_Selector.hxx>
#include <TNaming_Tool.hxx>
#include <TFunction_Function.hxx>
#include <TDataStd_Integer.hxx>
#include <ModelDefinitions.hxx>
//#define SEL_DEB 1
#ifdef SEL_DEB
#include <TDF_Tool.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
#endif
//=======================================================================
//function : DNaming_SelectionDriver
//purpose : Constructor
//=======================================================================
DNaming_SelectionDriver::DNaming_SelectionDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <theLog>.
//=======================================================================
void DNaming_SelectionDriver::Validate(TFunction_Logbook& ) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <theLog> if the loaded function must be
// executed (i.e.arguments are modified) or not.
//=======================================================================
Standard_Boolean DNaming_SelectionDriver::MustExecute(const TFunction_Logbook& ) const {
return Standard_True;
}
#ifdef SEL_DEB
#include <BRepTools.hxx>
static void Write(const TopoDS_Shape& shape,
const Standard_CString filename)
{
ofstream save;
save.open(filename);
save << "DBRep_DrawableShape" << endl << endl;
if(!shape.IsNull()) BRepTools::Write(shape, save);
save.close();
}
#endif
//=======================================================================
//function : Execute
//purpose : Execute the function and push in <theLog> the impacted
// labels (see method SetImpacted).
//=======================================================================
#include <TNaming_ListOfNamedShape.hxx>
#include <TDF_AttributeMap.hxx>
#include <TDF_IDFilter.hxx>
#include <TDF_Tool.hxx>
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDF_ChildIterator.hxx>
static void CollectLabels(const TDF_Label& theLabel, TDF_LabelMap& theMap) {
TDF_AttributeMap outRefs;
TDF_Tool::OutReferences(theLabel, outRefs);
for (TDF_MapIteratorOfAttributeMap itr(outRefs); itr.More(); itr.Next()) {
if (itr.Key()->DynamicType() == STANDARD_TYPE(TNaming_NamedShape)) {
theMap.Add(itr.Key()->Label());
CollectLabels(itr.Key()->Label(), theMap);
TCollection_AsciiString anEntry;
TDF_Tool::Entry(itr.Key()->Label(), anEntry);
cout << "NS refered Label = " << anEntry << endl;
}
}
}
Standard_Integer DNaming_SelectionDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
TDF_Label aRLabel = RESPOSITION(aFunction);
if(aRLabel.IsNull()) return -1;
Standard_Boolean aIsWire = Standard_False;
TopAbs_ShapeEnum aPrevShapeType = TopAbs_SHAPE;
Handle(TNaming_NamedShape) aNShape;
if(aRLabel.FindAttribute(TNaming_NamedShape::GetID(),aNShape)) {
if(!aNShape.IsNull() && !aNShape->IsEmpty()) {
aPrevShapeType = aNShape->Get().ShapeType();
if (aPrevShapeType == TopAbs_WIRE) aIsWire = Standard_True;
}
}
TNaming_Selector aSelector(aRLabel);
TDF_LabelMap aMap;
aMap = theLog.ChangeValid();
#ifdef SEL_DEB
cout <<"#E_DNaming_SelectionDriver:: Valid Label Map:"<<endl;
TDF_MapIteratorOfLabelMap anItr(aMap);
for (; anItr.More(); anItr.Next()) {
const TDF_Label& aLabel = anItr.Key();
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
cout << "\tLabel = " << anEntry << endl;
}
#endif
//***
// TDF_IDFilter aFilterForReferers;
// aFilterForReferers.Keep(TNaming_NamedShape::GetID());
// TDF_IDFilter aFilterForReferences;
// aFilterForReferences.Keep(TNaming_NamedShape::GetID());
// TDF_LabelMap aMap1;
// CollectLabels(aLabel, aMap1);
// TDF_Tool::OutReferences(aLabel, /*aFilterForReferers, aFilterForReferences, */outRefs);
//***
if(aSelector.Solve(aMap)) {
theLog.SetValid(aRLabel);
Handle(TNaming_NamedShape) aNS;
if(!aRLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
cout <<"%%%WARNING: DNaming_SelectionDriver::NamedShape is not found"<<endl;
}
else {
if(aNS.IsNull()) {
cout << "%%%WARNING: DNaming_SelectionDriver::NamedShape is NULL" <<endl;
} else
if(aNS->IsEmpty()) {
cout << "%%%WARNING: DNaming_SelectionDriver::NamedShape is EMPTY on Label = ";
aNS->Label().EntryDump(cout); cout << endl;
} else {
#ifdef SEL_DEB
Write(aNS->Get(), "Selection_Result.brep");
Handle(TopoDS_TShape) aTS = aNS->Get().TShape();
cout << "TShape = " << (Standard_Address)aTS <<endl;
#endif
if(aIsWire && aNS->Get().ShapeType()== TopAbs_COMPOUND) {
TopoDS_Shape aWireShape;
TNaming_Tool::FindShape(aMap, aMap, aNS, aWireShape);
TNaming_Builder aBuilder(aRLabel);
aBuilder.Select(aWireShape, aWireShape);
aFunction->SetFailure(DONE);
} else
if(aPrevShapeType == aNS->Get().ShapeType()) {
aFunction->SetFailure(DONE);
} else {
#ifdef SEL_DEB
cout <<"%%%WARNING: DNaming_SelectionDriver::Execute: The Shape after solving changed type = "<<aNS->Get().ShapeType()<< endl;
#endif
aFunction->SetFailure(DONE);
}
}
}
}
else {
aFunction->SetFailure(NOTDONE);
cout << "%%%WARNING: DNaming_SelectionDriver::Execute: Selection is Not solved !!!" << endl;
return 1;
}
return 0;
}

View File

@@ -0,0 +1,53 @@
-- File: DNaming_SphereDriver.cdl
-- Created: Thu Jun 18 14:30:28 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class SphereDriver from DNaming inherits Driver from TFunction
---Purpose:
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
MakeSphere from BRepPrimAPI,
Shape from TopoDS
is
Create returns mutable SphereDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; mkSphere : in out MakeSphere from BRepPrimAPI)
is private;
end SphereDriver;

View File

@@ -0,0 +1,187 @@
// File: DNaming_SphereDriver.cxx
// Created: Thu Jun 18 14:39:35 2009
// Author: Sergey ZARITCHNY
// <szy@petrox.nnov.matra-dtv.fr>
#include <DNaming_SphereDriver.ixx>
#include <gp_Ax2.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopExp.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <TopLoc_Location.hxx>
#include <BRepAlgo.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_UAttribute.hxx>
#include <TopoDS_Solid.hxx>
#include <TNaming.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Builder.hxx>
#include <TFunction_Function.hxx>
#include <DNaming.hxx>
#include <ModelDefinitions.hxx>
//=======================================================================
//function : DNaming_SphereDriver
//purpose : Constructor
//=======================================================================
DNaming_SphereDriver::DNaming_SphereDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <theLog>
//=======================================================================
void DNaming_SphereDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyses in <theLog> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_SphereDriver::MustExecute(const TFunction_Logbook& theLog) const {
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Executes the function
//=======================================================================
Standard_Integer DNaming_SphereDriver::Execute(TFunction_Logbook& theLog) const {
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
Standard_Real aRadius = DNaming::GetReal(aFunction,SPHERE_RADIUS)->Get();
Handle(TDataStd_UAttribute) anObject = DNaming::GetObjectArg(aFunction,SPHERE_CENTER);
Handle(TNaming_NamedShape) aNSCnt = DNaming::GetObjectValue(anObject);
if (aNSCnt.IsNull() || aNSCnt->IsEmpty()) {
#ifdef DEB
cout<<"SphereDriver:: Center point is null or empty"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
Handle(TNaming_NamedShape) aPrevSphere = DNaming::GetFunctionResult(aFunction);
// Save location
TopLoc_Location aLocation;
if (!aPrevSphere.IsNull() && !aPrevSphere->IsEmpty()) {
aLocation = aPrevSphere->Get().Location();
}
TopoDS_Shape aCntShape = aNSCnt->Get();
if(aCntShape.IsNull()) {
#ifdef DEB
cout<<"SphereDriver:: Center point is null"<<endl;
#endif
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
gp_Pnt aCenter = gp_Pnt(0.,0.,0.);
if(aCntShape.ShapeType() == TopAbs_VERTEX) {
aCenter = BRep_Tool::Pnt(TopoDS::Vertex(aCntShape));
}
gp_Ax2 anAxis = gp_Ax2(aCenter, gp_Dir(0,0,1), gp_Dir(1,0,0));
BRepPrimAPI_MakeSphere aMakeSphere(anAxis, aRadius);
aMakeSphere.Build();
if (!aMakeSphere.IsDone()) {
aFunction->SetFailure(ALGO_FAILED);
return -1;
}
TopoDS_Shape aResult = aMakeSphere.Solid();
if (!BRepAlgo::IsValid(aResult)) {
aFunction->SetFailure(RESULT_NOT_VALID);
return -1;
}
// Naming
LoadNamingDS(RESPOSITION(aFunction), aMakeSphere);
// restore location
if(!aLocation.IsIdentity())
TNaming::Displace(RESPOSITION(aFunction), aLocation, Standard_True);
theLog.SetValid(RESPOSITION(aFunction), Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=======================================================================
//function : LoadAndName
//purpose :
//=======================================================================
void DNaming_SphereDriver::LoadNamingDS (const TDF_Label& theResultLabel,
BRepPrimAPI_MakeSphere& MS) const
{
Handle(TDF_TagSource) Tagger = TDF_TagSource::Set(theResultLabel);
if (Tagger.IsNull()) return;
Tagger->Set(0);
TNaming_Builder Builder (theResultLabel);
Builder.Generated (MS.Solid());
BRepPrim_Sphere& S = MS.Sphere();
//Load faces of the Sph :
if (S.HasBottom()) {
TopoDS_Face BottomFace = S.BottomFace ();
TNaming_Builder BOF (theResultLabel.NewChild());
BOF.Generated (BottomFace);
}
if (S.HasTop()) {
TopoDS_Face TopFace = S.TopFace ();
TNaming_Builder TOF (theResultLabel.NewChild());
TOF.Generated (TopFace);
}
TopoDS_Face LateralFace = S.LateralFace();
TNaming_Builder LOF (theResultLabel.NewChild());
LOF.Generated(LateralFace);
if (S.HasSides()) {
TopoDS_Face StartFace = S.StartFace();
TNaming_Builder SF(theResultLabel.NewChild());
SF.Generated(StartFace);
TopoDS_Face EndFace = S.EndFace();
TNaming_Builder EF(theResultLabel.NewChild());
EF.Generated(EndFace);
}
TopTools_IndexedMapOfShape LateralEdges;
TopExp::MapShapes(LateralFace, TopAbs_EDGE, LateralEdges);
Standard_Integer i = 1;
TColStd_ListOfInteger goodEdges;
for (; i <= LateralEdges.Extent(); i++)
if (!BRep_Tool::Degenerated(TopoDS::Edge(LateralEdges.FindKey(i)))) goodEdges.Append(i);
if (goodEdges.Extent() == 1) {
const TopoDS_Edge& aLateralEdge = TopoDS::Edge(LateralEdges.FindKey(goodEdges.First()));
TNaming_Builder MeridianBuilder(theResultLabel.NewChild());
MeridianBuilder.Generated(aLateralEdge);
TopoDS_Iterator it(aLateralEdge);
for(;it.More();it.Next()) {
//const TopoDS_Shape& aV = it.Value();
TNaming_Builder aVBuilder(theResultLabel.NewChild());
aVBuilder.Generated(it.Value());
}
}
}

View File

@@ -0,0 +1,157 @@
// File: DNaming_ToolsCommands.cxx
// Created: Thu Jun 24 18:38:25 1999
// Author: Sergey ZARITCHNY
// <szy@philipox.nnov.matra-dtv.fr>
#include <Draw_Interpretor.hxx>
#include <Draw.hxx>
#include <DBRep.hxx>
#include <DNaming.hxx>
#include <BRepTools.hxx>
#include <TopoDS_Face.hxx>
#include <TopLoc_Location.hxx>
#include <BRep_Builder.hxx>
#include <gp_Pnt.hxx>
#include <TopExp_Explorer.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopAbs.hxx>
#include <TNaming_Translator.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
#include <DNaming_DataMapOfShapeOfName.hxx>
#include <DNaming_DataMapIteratorOfDataMapOfShapeOfName.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
//=======================================================================
//function : DNaming_CheckHasSame
//purpose : CheckIsSame Shape1 Shape2
// - for test ShapeCopy mechanism
//=======================================================================
static Standard_Integer DNaming_CheckHasSame (Draw_Interpretor& di,
Standard_Integer nb,
const char** arg)
{
if(nb < 4) return 1;
TopoDS_Shape S1 = DBRep::Get(arg[1]);
if ( S1.IsNull() ) {
BRep_Builder aBuilder;
BRepTools::Read( S1, arg[1], aBuilder);
}
TopoDS_Shape S2 = DBRep::Get(arg[2]);
if ( S2.IsNull() ) {
BRep_Builder aBuilder;
BRepTools::Read( S2, arg[2], aBuilder);
}
char M[8];
strcpy(M, arg[3]);
strtok(M, " \t");
TopAbs_ShapeEnum mod = TopAbs_FACE;
if(M[0] == 'F' || M[0] == 'f')
mod = TopAbs_FACE;
else if(M[0] == 'E' || M[0] == 'e')
mod = TopAbs_EDGE;
else if(M[0] == 'V' || M[0] == 'v')
mod = TopAbs_VERTEX;
else
return 1;
TopExp_Explorer Exp1, Exp2;
TopTools_MapOfShape M1, M2;
for(Exp1.Init(S1, mod);Exp1.More();Exp1.Next()) {
M1.Add(Exp1.Current());
}
for(Exp2.Init(S2, mod);Exp2.More();Exp2.Next()) {
M2.Add(Exp2.Current());
}
TopTools_MapIteratorOfMapOfShape itr1(M1);
TopTools_MapIteratorOfMapOfShape itr2;
for(;itr1.More();itr1.Next()) {
const TopoDS_Shape& s1 = itr1.Key();
for(itr2.Initialize(M2);itr2.More();itr2.Next()) {
const TopoDS_Shape& s2 = itr2.Key();
if(s1.IsSame(s2))
di << "Shapes " << arg[1]<< " and "<< arg[2]<< " have SAME subshapes" <<"\n";
}
}
return 0;
}
//=======================================================================
//function : DNaming_TCopyShape
//purpose : CopyShape Shape1 [Shape2 ...]
// - for test ShapeCopy mechanism
//=======================================================================
static Standard_Integer DNaming_TCopyShape (Draw_Interpretor& di,
Standard_Integer nb,
const char** arg)
{
TNaming_Translator TR;
if(nb < 2) return (1);
DNaming_DataMapOfShapeOfName aDMapOfShapeOfName;
for(Standard_Integer i= 1;i < nb; i++) {
TopoDS_Shape S = DBRep::Get(arg[i]);
TCollection_AsciiString name(arg[i]);
name.AssignCat("_c");
if ( S.IsNull() ) {
BRep_Builder aBuilder;
BRepTools::Read( S, arg[i], aBuilder);
}
// Add to Map
if(S.IsNull()) return(1);
else {
aDMapOfShapeOfName.Bind(S, name);
TR.Add(S);
}
} // for ...
// PERFORM
TR.Perform();
if(TR.IsDone()){
di << "DNaming_CopyShape:: Copy is Done " << "\n";
DNaming_DataMapIteratorOfDataMapOfShapeOfName itrn(aDMapOfShapeOfName);
for(;itrn.More();itrn.Next()) {
TCollection_AsciiString name = itrn.Value();
const TopoDS_Shape& Result = TR.Copied(itrn.Key());
DBRep::Set(name.ToCString(), Result);
di.AppendElement(name.ToCString());
}
return 0;
}
di << "DNaming_CopyShape : Error" << "\n";
return 1;
}
//=======================================================================
//function : ToolsCommands
//purpose :
//=======================================================================
void DNaming::ToolsCommands (Draw_Interpretor& theCommands)
{
static Standard_Boolean done = Standard_False;
if (done) return;
done = Standard_True;
const char* g = "Naming data commands " ;
const char* g2 = "Naming modeling commands" ;
theCommands.Add ("CopyShape",
"CopyShape (Shape1 [Shape2] ...)",
__FILE__, DNaming_TCopyShape, g);
theCommands.Add ("CheckSame",
"CheckSame (Shape1 Shape2 ExploMode[F|E|V])",
__FILE__, DNaming_CheckHasSame, g);
}

View File

@@ -0,0 +1,55 @@
-- File: DNaming_TransformationDriver.cdl
-- Created: Thu May 7 11:50:28 2009
-- Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
---Copyright: Open CasCade SA 2009
class TransformationDriver from DNaming inherits Driver from TFunction
---Purpose:
uses
Label from TDF,
Logbook from TFunction,
Function from TFunction,
ExtendedString from TCollection,
NamedShape from TNaming,
Trsf from gp
is
Create returns mutable TransformationDriver from DNaming;
---Purpose: Constructor
---Purpose: validation
-- ==========
Validate(me; theLog : in out Logbook from TFunction)
is redefined;
---Purpose: Validates labels of a function in <log>.
-- In regeneration mode this method must be called (by the
-- solver) even if the function is not executed, to build
-- the valid label scope.
---Purpose: execution of function
-- ======================
MustExecute (me; theLog : Logbook from TFunction)
---Purpose: Analyse in <log> if the loaded function must be executed
-- (i.e.arguments are modified) or not.
-- If the Function label itself is modified, the function must
-- be executed.
returns Boolean from Standard
is redefined;
Execute (me; theLog : in out Logbook from TFunction)
---Purpose: Execute the function and push in <log> the impacted
-- labels (see method SetImpacted).
returns Integer from Standard
is redefined;
LoadNamingDS(me; theResultLabel : Label from TDF; theSourceNS : NamedShape from TNaming;
theTrsf : Trsf from gp)
is private;
end TransformationDriver;

View File

@@ -0,0 +1,449 @@
// File: DNaming_TransformationDriver.cxx
// Created: Thu May 7 11:55:58 2009
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2009
#include <DNaming_TransformationDriver.ixx>
#include <Standard_NullObject.hxx>
#include <TopAbs.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRep_Tool.hxx>
#include <BRepBuilderAPI_MakeShape.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TopTools_DataMapOfShapeShape.hxx>
#include <TopTools_MapIteratorOfMapOfShape.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
#include <TopTools_DataMapOfShapeInteger.hxx>
#include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TNaming_Tool.hxx>
#include <TFunction_Function.hxx>
#include <TFunction_Logbook.hxx>
#include <DNaming.hxx>
#include <TDataStd_Real.hxx>
#include <gp_Vec.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pln.hxx>
#include <GeomLib_IsPlanarSurface.hxx>
#include <ModelDefinitions.hxx>
#ifdef WNT
#define EXCEPTION ...
#else
#define EXCEPTION Standard_Failure
#endif
#define FACES_TAG 1
#define EDGES_TAG 2
#define VERTEX_TAG 3
//#define MDTV_DEB_TRSF
#ifdef MDTV_DEB_TRSF
#include <TCollection_AsciiString.hxx>
#include <BRepTools.hxx>
#include <TDF_Tool.hxx>
void PrintE(const TDF_Label& label)
{
TCollection_AsciiString entry;
TDF_Tool::Entry(label, entry);
cout << "LabelEntry = "<< entry << endl;
}
#endif
//=======================================================================
//function : TransformationDriver
//purpose : Constructor
//=======================================================================
DNaming_TransformationDriver::DNaming_TransformationDriver()
{}
//=======================================================================
//function : Validate
//purpose : Validates labels of a function in <log>.
//=======================================================================
void DNaming_TransformationDriver::Validate(TFunction_Logbook& theLog) const
{}
//=======================================================================
//function : MustExecute
//purpose : Analyse in <log> if the loaded function must be executed
//=======================================================================
Standard_Boolean DNaming_TransformationDriver::MustExecute(const TFunction_Logbook& theLog) const
{
return Standard_True;
}
//=======================================================================
//function : Execute
//purpose : Execute the function and push in <log> the impacted labels
//=======================================================================
Standard_Integer DNaming_TransformationDriver::Execute(TFunction_Logbook& theLog) const
{
Handle(TFunction_Function) aFunction;
Label().FindAttribute(TFunction_Function::GetID(),aFunction);
if(aFunction.IsNull()) return -1;
Handle(TFunction_Function) aPrevFun = DNaming::GetPrevFunction(aFunction);
if(aPrevFun.IsNull()) return -1;
const TDF_Label& aLab = RESPOSITION(aPrevFun);
Handle(TNaming_NamedShape) aContextNS;
aLab.FindAttribute(TNaming_NamedShape::GetID(), aContextNS);
if (aContextNS.IsNull() || aContextNS->IsEmpty()) {
#ifdef DEB
cout<<"TransformationDriver:: Context is empty"<<endl;
#endif
aFunction->SetFailure(WRONG_CONTEXT);
return -1;
}
//
gp_Trsf aTransformation;
const Standard_GUID& aGUID = aFunction->GetDriverGUID();
try {
if(aGUID == PTXYZ_GUID) {
Standard_Real aDX = DNaming::GetReal(aFunction,PTRANSF_DX)->Get();
Standard_Real aDY = DNaming::GetReal(aFunction,PTRANSF_DY)->Get();
Standard_Real aDZ = DNaming::GetReal(aFunction,PTRANSF_DZ)->Get();
gp_Vec aVector(aDX, aDY, aDZ);
aTransformation.SetTranslation(aVector);
}
else if(aGUID == PTALINE_GUID) {
Handle(TDataStd_UAttribute) aLineObj = DNaming::GetObjectArg(aFunction, PTRANSF_LINE);
Handle(TNaming_NamedShape) aLineNS = DNaming::GetObjectValue(aLineObj);
gp_Ax1 anAxis;
if(!DNaming::ComputeAxis(aLineNS, anAxis)) Standard_Failure::Raise();
gp_Vec aVector(anAxis.Direction());
aVector.Normalize();
Standard_Real anOffset = DNaming::GetReal(aFunction,PTRANSF_OFF)->Get();
aVector *= anOffset;
aTransformation.SetTranslation(aVector);
} else if(aGUID == PRRLINE_GUID) {
Handle(TDataStd_UAttribute) aLineObj = DNaming::GetObjectArg(aFunction, PTRANSF_LINE);
Handle(TNaming_NamedShape) aLineNS = DNaming::GetObjectValue(aLineObj);
gp_Ax1 anAxis;
if(!DNaming::ComputeAxis(aLineNS, anAxis)) Standard_Failure::Raise();
Standard_Real anAngle = DNaming::GetReal(aFunction,PTRANSF_ANG)->Get();
aTransformation.SetRotation(anAxis, anAngle);
} else if(aGUID == PMIRR_GUID) {
Handle(TDataStd_UAttribute) aPlaneObj = DNaming::GetObjectArg(aFunction, PTRANSF_PLANE);
Handle(TNaming_NamedShape) aNS = DNaming::GetObjectValue(aPlaneObj);
if(aNS.IsNull() || aNS->IsEmpty() || aNS->Get().IsNull() ||
aNS->Get().ShapeType() != TopAbs_FACE) Standard_Failure::Raise();
TopoDS_Face aFace = TopoDS::Face(aNS->Get());
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
GeomLib_IsPlanarSurface isPlanarSurface (aSurf);
if(!isPlanarSurface.IsPlanar()) Standard_Failure::Raise();
gp_Pln aPlane = isPlanarSurface.Plan();
gp_Ax2 aMirrorAx2 = aPlane.Position().Ax2();
aTransformation.SetMirror(aMirrorAx2);
} else {
aFunction->SetFailure(UNSUPPORTED_FUNCTION);
return -1;
}
} catch (EXCEPTION) {
aFunction->SetFailure(WRONG_ARGUMENT);
return -1;
}
//
// Naming
LoadNamingDS(RESPOSITION(aFunction), aContextNS, aTransformation);
theLog.SetValid(RESPOSITION(aFunction),Standard_True);
aFunction->SetFailure(DONE);
return 0;
}
//=================================================================================
static void BuildMap(const TopTools_MapOfShape& SMap,
BRepBuilderAPI_Transform& Transformer,
TopTools_DataMapOfShapeShape& M)
{
TopTools_MapIteratorOfMapOfShape anIt(SMap);
for(;anIt.More();anIt.Next()) {
if(!anIt.Key().IsNull()) {
const TopoDS_Shape& aS = anIt.Key();
M.Bind(aS,Transformer.ModifiedShape(aS));
}
}
}
//=================================================================================
static void CollectShapes(const TopoDS_Shape& SSh, TopoDS_Compound& C,
TopTools_MapOfShape& SMap, const TDF_Label& theLab,
TopTools_DataMapOfShapeInteger& TagMap, const Standard_Boolean isPrimitive)
{
const TopAbs_ShapeEnum aType = SSh.ShapeType();
BRep_Builder aB;
switch(aType) {
case TopAbs_COMPOUND:
{
TopoDS_Iterator it(SSh);
for(;it.More();it.Next())
CollectShapes(it.Value(), C, SMap, theLab, TagMap,isPrimitive);
}
break;
case TopAbs_COMPSOLID:
case TopAbs_SOLID:
case TopAbs_SHELL:
{
TopExp_Explorer anEx(SSh, TopAbs_FACE);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
anEx.Init(SSh, TopAbs_EDGE);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
anEx.Init(SSh, TopAbs_VERTEX);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
}
break;
case TopAbs_FACE:
{
const Handle(TNaming_NamedShape) aNamedShape = TNaming_Tool::NamedShape(SSh, theLab);
if(!aNamedShape.IsNull())
if(SMap.Add(SSh))
aB.Add(C,SSh);
TopExp_Explorer anEx(SSh, TopAbs_EDGE);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
anEx.Init(SSh, TopAbs_VERTEX);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
}
break;
case TopAbs_WIRE:
{
TopExp_Explorer anEx(SSh, TopAbs_EDGE);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
anEx.Init(SSh, TopAbs_VERTEX);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
}
break;
case TopAbs_EDGE:
{
const Handle(TNaming_NamedShape) aNamedShape = TNaming_Tool::NamedShape(SSh, theLab);
if(!aNamedShape.IsNull())
if(SMap.Add(SSh))
aB.Add(C,SSh);
TopExp_Explorer anEx(SSh, TopAbs_VERTEX);
anEx.Init(SSh, TopAbs_VERTEX);
for(;anEx.More();anEx.Next()) {
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(anEx.Current(), theLab);
if(aNS.IsNull()) continue;
if(SMap.Add(anEx.Current())) {
aB.Add(C,anEx.Current());
if(isPrimitive)
TagMap.Bind(anEx.Current(), aNS->Label().Tag());
}
}
}
break;
case TopAbs_VERTEX:
const Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SSh, theLab);
if(!aNS.IsNull())
if(SMap.Add(SSh)) {
aB.Add(C,SSh);
// if(isPrimitive)
// TagMap.Bind(SSh, aNS->Label().Tag());
}
break;
}
}
//=======================================================================
//function : LoadAndName
//purpose :
//=======================================================================
void DNaming_TransformationDriver::LoadNamingDS (const TDF_Label& theResultLabel,
const Handle(TNaming_NamedShape)& theSourceNS,
const gp_Trsf& theTrsf) const
{
TNaming_Builder aBuilder (theResultLabel);
if(theSourceNS.IsNull() || theSourceNS->IsEmpty())
return;
const TopoDS_Shape& aSrcShape = theSourceNS->Get();
if (aSrcShape.IsNull()) {
#ifdef DEB
cout<<"DNaming_TransformationDriver::LoadNamingDS: The result of the Transform operation is null"<<endl;
#endif
return;
}
Standard_Boolean isPrimitive(Standard_False);
if(theSourceNS->Evolution() == TNaming_PRIMITIVE) isPrimitive = Standard_True;
const TDF_Label& aSrcLabel = theSourceNS->Label();
#ifdef MDTV_DEB_TRSF
cout <<"TransformationDriver: ";
PrintE(aSrcLabel);
#endif
TopoDS_Compound aCompShape;
BRep_Builder aB;
aB.MakeCompound(aCompShape);
TopTools_MapOfShape aSMap;
TopTools_DataMapOfShapeInteger aTagMap;
//Collect shapes
if(aSMap.Add(aSrcShape))
aB.Add(aCompShape, aSrcShape);
CollectShapes(aSrcShape,aCompShape,aSMap, aSrcLabel, aTagMap, isPrimitive);
//Transform
BRepBuilderAPI_Transform aTransformer(aCompShape, theTrsf, Standard_False);
TopTools_DataMapOfShapeShape aTMap;
BuildMap (aSMap, aTransformer,aTMap);
//Load
TopoDS_Shape aNewSh;
if (aTMap.IsBound(aSrcShape)) aNewSh = aTMap(aSrcShape);
if(!aNewSh.IsNull()) {
aBuilder.Modify(aSrcShape, aNewSh);
aTMap.UnBind(aSrcShape);
}
TopTools_DataMapOfShapeShape SubShapes;
TopExp_Explorer Exp(aNewSh, TopAbs_FACE);
for (; Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
for (Exp.Init(aNewSh, TopAbs_EDGE); Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
for (Exp.Init(aNewSh, TopAbs_VERTEX); Exp.More(); Exp.Next()) {
SubShapes.Bind(Exp.Current(),Exp.Current());
}
Standard_Integer aNextTag(0);
TopTools_DataMapIteratorOfDataMapOfShapeInteger it(aTagMap);
for(;it.More();it.Next()) {
if(it.Value() > aNextTag)
aNextTag = it.Value();
}
TopTools_DataMapIteratorOfDataMapOfShapeShape anIt(aTMap);
Standard_Boolean aF, anE, aV;
aF = anE = aV = Standard_True;
TNaming_Builder* pB1;
TNaming_Builder* pB2;
TNaming_Builder* pB3;
for(;anIt.More();anIt.Next()) {
const TopoDS_Shape& aKey = anIt.Key();
TopoDS_Shape newShape = anIt.Value();
if(isPrimitive) {
if (SubShapes.IsBound(newShape)) {
newShape.Orientation((SubShapes(newShape)).Orientation());
}
if(aTagMap.IsBound(aKey)) {
const TDF_Label& aLabel = theResultLabel.FindChild(aTagMap.Find(aKey), Standard_True);
TNaming_Builder aBuilder(aLabel);
aBuilder.Modify(aKey, newShape);
} else {
aNextTag++;
const TDF_Label& aLabel = theResultLabel.FindChild(aNextTag, Standard_True);
TNaming_Builder aBuilder(aLabel);
aBuilder.Modify(aKey, newShape);
}
} else {
if(aKey.ShapeType() == TopAbs_FACE) {
if(aF) {
const TDF_Label& aFLabel = theResultLabel.FindChild(FACES_TAG, Standard_True);
TNaming_Builder aFBuilder(aFLabel);
pB1 = &aFBuilder;
aF = Standard_False;
}
if (SubShapes.IsBound(newShape)) {
newShape.Orientation((SubShapes(newShape)).Orientation());
}
pB1->Modify(anIt.Key(), newShape);
}
else if(aKey.ShapeType() == TopAbs_EDGE) {
if(anE) {
const TDF_Label& aELabel = theResultLabel.FindChild(EDGES_TAG, Standard_True);
TNaming_Builder anEBuilder(aELabel);
pB2 = &anEBuilder;
anE = Standard_False;
}
if (SubShapes.IsBound(newShape)) {
newShape.Orientation((SubShapes(newShape)).Orientation());
}
pB2->Modify(anIt.Key(), newShape);
}
else if(aKey.ShapeType() == TopAbs_VERTEX) {
if(aV) {
const TDF_Label& aVLabel = theResultLabel.FindChild(VERTEX_TAG, Standard_True);
TNaming_Builder aVBuilder(aVLabel);
pB3 = &aVBuilder;
aV = Standard_False;
}
if (SubShapes.IsBound(newShape)) {
newShape.Orientation((SubShapes(newShape)).Orientation());
}
pB3->Modify(anIt.Key(), newShape);
}
}
}
}

6
src/DNaming/FILES Executable file
View File

@@ -0,0 +1,6 @@
DNaming_BasicCommands.cxx
DNaming_ToolsCommands.cxx
DNaming_SelectionCommands.cxx
DNaming_ModelingCommands.cxx
DNaming_Selection.tcl
ModelDefinitions.hxx

View File

@@ -0,0 +1,89 @@
// File: ModelDefinitions.hxx
// Created: Thu Apr 30 12:07:06 2009
// Author: Sergey ZARITCHNY <sergey.zaritchny@opencascade.com>
// Copyright: Open CasCade SA 2009
#ifndef ModelDefinitions_HeaderFile
#define ModelDefinitions_HeaderFile
#define GEOMOBJECT_GUID Standard_GUID("6c6915ab-775f-4475-859e-befd74d26a23")
#define ATTCH_GUID Standard_GUID("12e94554-6dbc-11d4-b9c8-0060b0ee281b")
#define XTTCH_GUID Standard_GUID("12e94555-6dbc-11d4-b9c8-0060b0ee281b")
#define PTXYZ_GUID Standard_GUID("12e94556-6dbc-11d4-b9c8-0060b0ee281b")
#define PTALINE_GUID Standard_GUID("12e94557-6dbc-11d4-b9c8-0060b0ee281b")
#define PRRLINE_GUID Standard_GUID("12e94558-6dbc-11d4-b9c8-0060b0ee281b")
#define PMIRR_GUID Standard_GUID("12e94559-6dbc-11d4-b9c8-0060b0ee281b")
#define BOX_GUID Standard_GUID("12e94543-6dbc-11d4-b9c8-0060b0ee281b")
#define SPH_GUID Standard_GUID("12e94544-6dbc-11d4-b9c8-0060b0ee281b")
#define CYL_GUID Standard_GUID("12e94545-6dbc-11d4-b9c8-0060b0ee281b")
#define CONE_GUID Standard_GUID("12e94546-6dbc-11d4-b9c8-0060b0ee281b")
#define TORUS_GUID Standard_GUID("12e94547-6dbc-11d4-b9c8-0060b0ee281b")
#define CUT_GUID Standard_GUID("12e94548-6dbc-11d4-b9c8-0060b0ee281b")
#define FUSE_GUID Standard_GUID("12e94549-6dbc-11d4-b9c8-0060b0ee281b")
#define COMMON_GUID Standard_GUID("12e9454a-6dbc-11d4-b9c8-0060b0ee281b")
#define PRISM_GUID Standard_GUID("12e94550-6dbc-11d4-b9c8-0060b0ee281b")
#define FULREVOL_GUID Standard_GUID("12e94551-6dbc-11d4-b9c8-0060b0ee281b")
#define SECREVOL_GUID Standard_GUID("12e94552-6dbc-11d4-b9c8-0060b0ee281b")
#define FILLT_GUID Standard_GUID("12e94553-6dbc-11d4-b9c8-0060b0ee281b")
#define CHAMF_GUID Standard_GUID("12e9455a-6dbc-11d4-b9c8-0060b0ee281b")
#define OFFSET_GUID Standard_GUID("12e9455b-6dbc-11d4-b9c8-0060b0ee281b")
#define PNTXYZ_GUID Standard_GUID("12e9455c-6dbc-11d4-b9c8-0060b0ee281b")
#define PNTRLT_GUID Standard_GUID("12e9455d-6dbc-11d4-b9c8-0060b0ee281b")
#define LINE3D_GUID Standard_GUID("12e9455e-6dbc-11d4-b9c8-0060b0ee281b")
#define WIRE_GUID Standard_GUID("12e9455f-6dbc-11d4-b9c8-0060b0ee281b")
//Function structure definitions
#define FUNCTION_ARGUMENTS_LABEL 1
#define FUNCTION_RESULT_LABEL 2
#define POSITION(Function,theA) Function->Label().FindChild(FUNCTION_ARGUMENTS_LABEL).FindChild(theA)
#define RESPOSITION(Function) Function->Label().FindChild(FUNCTION_RESULT_LABEL)
#define BOX_DX 1
#define BOX_DY 2
#define BOX_DZ 3
#define CYL_RADIUS 1
#define CYL_HEIGHT 2
#define CYL_AXIS 3
#define ATTACH_ARG 1
#define BOOL_TOOL 1
#define FILLET_RADIUS 1
#define FILLET_SURFTYPE 2
#define FILLET_PATH 3
#define PTRANSF_DX 1
#define PTRANSF_DY 2
#define PTRANSF_DZ 3
#define PTRANSF_OFF 1
#define PTRANSF_ANG 1
#define PTRANSF_LINE 2
#define PTRANSF_PLANE 1
#define PRISM_BASIS 1
#define PRISM_HEIGHT 2
#define PRISM_DIR 3
#define REVOL_BASIS 1
#define REVOL_AXIS 2
#define REVOL_ANGLE 3
#define REVOL_REV 4
#define SPHERE_CENTER 1
#define SPHERE_RADIUS 2
#define PNT_DX 1
#define PNT_DY 2
#define PNT_DZ 3
#define PNTRLT_REF 4
#define LINE3D_TYPE 1
#define LINE3D_PNTNB 2
#define DONE 0
#define NOTDONE 9999
#define ALGO_FAILED 11
#define RESULT_NOT_VALID 12
#define WRONG_AXIS 13
#define WRONG_ARGUMENT 14
#define UNSUPPORTED_FUNCTION 15
#define NULL_RESULT 16
#define WRONG_CONTEXT 14
#define NAMING_FAILED 15
#endif