[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
committed by
WandererFan
parent
e42e9a4096
commit
a930658000
@@ -599,11 +599,13 @@ private:
|
||||
writer.setLayerName(layerName);
|
||||
TopoDS_Shape shapeToExport;
|
||||
if (SketchExportHelper::isSketch(obj)) {
|
||||
// project sketch along sketch Z via hlrProjector to get geometry on XY plane
|
||||
// project sketch along sketch Z via hlrProjector to get geometry on XY
|
||||
// plane
|
||||
shapeToExport = SketchExportHelper::getFlatSketchXY(obj);
|
||||
} else {
|
||||
// do we know that obj is a Part::Feature? is this checked somewhere before this?
|
||||
// this should be a located shape??
|
||||
}
|
||||
else {
|
||||
// do we know that obj is a Part::Feature? is this checked somewhere
|
||||
// before this? this should be a located shape??
|
||||
Part::Feature* part = static_cast<Part::Feature*>(obj);
|
||||
shapeToExport = part->Shape.getValue();
|
||||
}
|
||||
@@ -631,7 +633,8 @@ private:
|
||||
filePath = std::string(fname);
|
||||
layerName = "none";
|
||||
PyMem_Free(fname);
|
||||
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(docObj)->getDocumentObjectPtr();
|
||||
App::DocumentObject* obj =
|
||||
static_cast<App::DocumentObjectPy*>(docObj)->getDocumentObjectPtr();
|
||||
Base::Console().Message("Imp:writeDXFObject - docObj: %s\n", obj->getNameInDocument());
|
||||
|
||||
if ((versionParm == 12) || (versionParm == 14)) {
|
||||
@@ -663,8 +666,10 @@ private:
|
||||
if (SketchExportHelper::isSketch(obj)) {
|
||||
// project sketch along sketch Z via hlrProjector to get geometry on XY plane
|
||||
shapeToExport = SketchExportHelper::getFlatSketchXY(obj);
|
||||
} else {
|
||||
// TODO: do we know that obj is a Part::Feature? is this checked somewhere before this?
|
||||
}
|
||||
else {
|
||||
// TODO: do we know that obj is a Part::Feature? is this checked somewhere
|
||||
// before this?
|
||||
// TODO: this should be a located shape??
|
||||
Part::Feature* part = static_cast<Part::Feature*>(obj);
|
||||
shapeToExport = part->Shape.getValue();
|
||||
|
||||
@@ -43,73 +43,74 @@
|
||||
|
||||
using namespace Import;
|
||||
|
||||
//! project a shape so that it is represented as a flat shape on the XY plane. Z coordinate information
|
||||
//! is lost in this process, so it should only be used for flat objects like sketches.
|
||||
//! Note: this only returns hard and outline edges. Seam, smooth, isoparametric and hidden lines are not returned.
|
||||
TopoDS_Shape SketchExportHelper::projectShape(const TopoDS_Shape& inShape, const gp_Ax2& projectionCS)
|
||||
//! project a shape so that it is represented as a flat shape on the XY plane. Z coordinate
|
||||
//! information is lost in this process, so it should only be used for flat objects like sketches.
|
||||
//! Note: this only returns hard and outline edges. Seam, smooth, isoparametric and hidden lines
|
||||
//! are not returned.
|
||||
TopoDS_Shape SketchExportHelper::projectShape(const TopoDS_Shape& inShape,
|
||||
const gp_Ax2& projectionCS)
|
||||
{
|
||||
Handle(HLRBRep_Algo) brep_hlr = new HLRBRep_Algo();
|
||||
brep_hlr->Add(inShape);
|
||||
HLRAlgo_Projector projector(projectionCS);
|
||||
brep_hlr->Projector(projector);
|
||||
brep_hlr->Update();
|
||||
brep_hlr->Hide();
|
||||
HLRBRep_HLRToShape hlrToShape(brep_hlr);
|
||||
BRep_Builder builder;
|
||||
TopoDS_Compound comp;
|
||||
builder.MakeCompound(comp);
|
||||
if (!hlrToShape.VCompound().IsNull()) {
|
||||
builder.Add(comp, hlrToShape.VCompound());
|
||||
}
|
||||
if (!hlrToShape.OutLineVCompound().IsNull()) {
|
||||
builder.Add(comp, hlrToShape.OutLineVCompound());
|
||||
}
|
||||
return comp;
|
||||
Handle(HLRBRep_Algo) brep_hlr = new HLRBRep_Algo();
|
||||
brep_hlr->Add(inShape);
|
||||
HLRAlgo_Projector projector(projectionCS);
|
||||
brep_hlr->Projector(projector);
|
||||
brep_hlr->Update();
|
||||
brep_hlr->Hide();
|
||||
HLRBRep_HLRToShape hlrToShape(brep_hlr);
|
||||
BRep_Builder builder;
|
||||
TopoDS_Compound comp;
|
||||
builder.MakeCompound(comp);
|
||||
if (!hlrToShape.VCompound().IsNull()) {
|
||||
builder.Add(comp, hlrToShape.VCompound());
|
||||
}
|
||||
if (!hlrToShape.OutLineVCompound().IsNull()) {
|
||||
builder.Add(comp, hlrToShape.OutLineVCompound());
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
|
||||
//! true if obj is a sketch
|
||||
bool SketchExportHelper::isSketch(App::DocumentObject* obj)
|
||||
{
|
||||
// TODO:: the check for an object being a sketch should be done as in the commented
|
||||
// if statement below. To do this, we need to include Mod/Sketcher/SketchObject.h,
|
||||
// but that makes Import dependent on Eigen libraries which we don't use. As a
|
||||
// workaround we will inspect the object's class name.
|
||||
// if (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
|
||||
std::string objTypeName = obj->getTypeId().getName();
|
||||
std::string sketcherToken("Sketcher");
|
||||
return objTypeName.find(sketcherToken) != std::string::npos;
|
||||
}
|
||||
bool SketchExportHelper::isSketch(App::DocumentObject* obj)
|
||||
{
|
||||
// TODO:: the check for an object being a sketch should be done as in the commented
|
||||
// if statement below. To do this, we need to include Mod/Sketcher/SketchObject.h,
|
||||
// but that makes Import dependent on Eigen libraries which we don't use. As a
|
||||
// workaround we will inspect the object's class name.
|
||||
// if (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
|
||||
std::string objTypeName = obj->getTypeId().getName();
|
||||
std::string sketcherToken("Sketcher");
|
||||
return objTypeName.find(sketcherToken) != std::string::npos;
|
||||
}
|
||||
|
||||
|
||||
//! return a version of a sketch's geometry mapped to the OXYZ coordinate system
|
||||
//! preferred by dxf
|
||||
TopoDS_Shape SketchExportHelper::getFlatSketchXY(App::DocumentObject* obj)
|
||||
{
|
||||
// since we can't reference Sketcher module here, we will cast obj to
|
||||
// a Part::Feature instead
|
||||
auto sketch = dynamic_cast<Part::Feature*>(obj);
|
||||
if ( !sketch || !isSketch(obj)){
|
||||
return {};
|
||||
}
|
||||
|
||||
auto plm = sketch->Placement.getValue();
|
||||
Base::Rotation rot = plm.getRotation();
|
||||
|
||||
//get the sketch normal
|
||||
Base::Vector3d stdZ{0.0, 0.0, 1.0};
|
||||
Base::Vector3d sketchNormal;
|
||||
rot.multVec(stdZ, sketchNormal);
|
||||
Base::Vector3d stdX{1.0, 0.0, 0.0};
|
||||
Base::Vector3d sketchX;
|
||||
rot.multVec(stdX, sketchX);
|
||||
|
||||
//get the sketch origin
|
||||
Base::Vector3d position = plm.getPosition();
|
||||
gp_Ax2 projectionCS(gp_Pnt(position.x, position.y, position.z),
|
||||
gp_Dir(sketchNormal.x, sketchNormal.y, sketchNormal.z),
|
||||
gp_Dir(sketchX.x, sketchX.y, sketchX.z));
|
||||
const TopoDS_Shape& shape = sketch->Shape.getValue();
|
||||
return projectShape(shape, projectionCS);
|
||||
TopoDS_Shape SketchExportHelper::getFlatSketchXY(App::DocumentObject* obj)
|
||||
{
|
||||
// since we can't reference Sketcher module here, we will cast obj to
|
||||
// a Part::Feature instead
|
||||
auto sketch = dynamic_cast<Part::Feature*>(obj);
|
||||
if (!sketch || !isSketch(obj)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto plm = sketch->Placement.getValue();
|
||||
Base::Rotation rot = plm.getRotation();
|
||||
|
||||
// get the sketch normal
|
||||
Base::Vector3d stdZ {0.0, 0.0, 1.0};
|
||||
Base::Vector3d sketchNormal;
|
||||
rot.multVec(stdZ, sketchNormal);
|
||||
Base::Vector3d stdX {1.0, 0.0, 0.0};
|
||||
Base::Vector3d sketchX;
|
||||
rot.multVec(stdX, sketchX);
|
||||
|
||||
// get the sketch origin
|
||||
Base::Vector3d position = plm.getPosition();
|
||||
gp_Ax2 projectionCS(gp_Pnt(position.x, position.y, position.z),
|
||||
gp_Dir(sketchNormal.x, sketchNormal.y, sketchNormal.z),
|
||||
gp_Dir(sketchX.x, sketchX.y, sketchX.z));
|
||||
const TopoDS_Shape& shape = sketch->Shape.getValue();
|
||||
return projectShape(shape, projectionCS);
|
||||
}
|
||||
|
||||
@@ -43,4 +43,4 @@ public:
|
||||
static TopoDS_Shape getFlatSketchXY(App::DocumentObject* obj);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Import
|
||||
|
||||
@@ -692,8 +692,8 @@ void CDxfWrite::writePoint(const double* point)
|
||||
(*m_ssEntity) << point[2] << endl; // Z in WCS coordinates
|
||||
}
|
||||
|
||||
//! arc from 3 points - start, end, center. dir true if arc is AntiClockwise. unspecified assumption is that
|
||||
//! points are on XY plane in coord system OXYZ.
|
||||
//! arc from 3 points - start, end, center. dir true if arc is AntiClockwise. unspecified assumption
|
||||
//! is that points are on XY plane in coord system OXYZ.
|
||||
void CDxfWrite::writeArc(const double* start, const double* end, const double* center, bool dir)
|
||||
|
||||
{
|
||||
@@ -769,10 +769,10 @@ void CDxfWrite::writeCircle(const double* center, double radius)
|
||||
(*m_ssEntity) << center[0] << endl; // X in WCS coordinates
|
||||
(*m_ssEntity) << " 20" << endl;
|
||||
(*m_ssEntity) << center[1] << endl; // Y in WCS coordinates
|
||||
(*m_ssEntity) << " 30" << endl;
|
||||
(*m_ssEntity) << center[2] << endl; // Z in WCS coordinates
|
||||
(*m_ssEntity) << " 40" << endl; //
|
||||
(*m_ssEntity) << radius << endl; // Radius
|
||||
(*m_ssEntity) << " 30" << endl;
|
||||
(*m_ssEntity) << center[2] << endl; // Z in WCS coordinates
|
||||
(*m_ssEntity) << " 40" << endl; //
|
||||
(*m_ssEntity) << radius << endl; // Radius
|
||||
}
|
||||
|
||||
void CDxfWrite::writeEllipse(const double* center,
|
||||
@@ -820,7 +820,8 @@ void CDxfWrite::writeEllipse(const double* center,
|
||||
(*m_ssEntity) << " 31" << endl;
|
||||
(*m_ssEntity) << m.z << endl; // Major Z
|
||||
(*m_ssEntity) << " 40" << endl; //
|
||||
(*m_ssEntity) << ratio << endl; // Ratio
|
||||
(*m_ssEntity) << ratio
|
||||
<< endl; // Ratio
|
||||
// (*m_ssEntity) << "210" << endl; //extrusion dir??
|
||||
// (*m_ssEntity) << "0" << endl;
|
||||
// (*m_ssEntity) << "220" << endl;
|
||||
|
||||
Reference in New Issue
Block a user