Skip to content

Commit

Permalink
[TD]Save geometry and tag with centerline
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Nov 7, 2019
1 parent 900a7c6 commit fcf5435
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 71 deletions.
172 changes: 103 additions & 69 deletions src/Mod/TechDraw/App/Cosmetic.cpp
Expand Up @@ -455,7 +455,7 @@ void CosmeticEdge::Save(Base::Writer &writer) const
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*>(m_geometry);
aoc->Save(writer);
} else {
Base::Console().Message("CE::Save - unimplemented geomType: %d\n", m_geometry->geomType);
Base::Console().Warning("CE::Save - unimplemented geomType: %d\n", m_geometry->geomType);
}
}

Expand Down Expand Up @@ -490,7 +490,7 @@ void CosmeticEdge::Restore(Base::XMLReader &reader)
aoc->occEdge = GeometryUtils::edgeFromCircleArc(aoc);
m_geometry = (TechDraw::BaseGeom*) aoc;
} else {
Base::Console().Message("CE::Restore - unimplemented geomType: %d\n", gType);
Base::Console().Warning("CE::Restore - unimplemented geomType: %d\n", gType);
}
}

Expand Down Expand Up @@ -569,7 +569,7 @@ CenterLine::CenterLine(void)

m_geometry = new TechDraw::BaseGeom();

createNewTag();
initialize();
}

CenterLine::CenterLine(CenterLine* cl)
Expand All @@ -590,9 +590,10 @@ CenterLine::CenterLine(CenterLine* cl)

TechDraw::BaseGeom* newGeom = cl->m_geometry->copy();
m_geometry = newGeom;
m_format = cl->m_format;

createNewTag();
initialize();

m_format = cl->m_format;
}

CenterLine::CenterLine(Base::Vector3d pt1, Base::Vector3d pt2)
Expand All @@ -614,7 +615,7 @@ CenterLine::CenterLine(Base::Vector3d pt1, Base::Vector3d pt2)
TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2);
m_geometry = TechDraw::BaseGeom::baseFactory(e);

createNewTag();
initialize();
}

CenterLine::CenterLine(Base::Vector3d pt1, Base::Vector3d pt2,
Expand Down Expand Up @@ -642,13 +643,24 @@ CenterLine::CenterLine(Base::Vector3d pt1, Base::Vector3d pt2,
TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2);
m_geometry = TechDraw::BaseGeom::baseFactory(e);

createNewTag();
initialize();
}

CenterLine::~CenterLine()
{
}

void CenterLine::initialize()
{
m_geometry->classOfEdge = ecHARD;
m_geometry->hlrVisible = true;
m_geometry->cosmetic = true;
m_geometry->source(CENTERLINE);

createNewTag();
m_geometry->setCosmeticTag(getTagAsString());
}

CenterLine* CenterLine::CenterLineBuilder(DrawViewPart* partFeat,
std::vector<std::string> subNames,
int mode,
Expand Down Expand Up @@ -717,25 +729,32 @@ TechDraw::BaseGeom* CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFeat)
}

std::pair<Base::Vector3d, Base::Vector3d> ends;
if (m_type == CLTYPE::FACE) {
ends = calcEndPoints(partFeat,
m_faces,
m_mode, m_extendBy,
m_hShift,m_vShift, m_rotate);
} else if (m_type == CLTYPE::EDGE) {
ends = calcEndPoints2Lines(partFeat,
m_edges,
m_mode,
m_extendBy,
m_hShift, m_vShift, m_rotate, m_flip2Line);
} else if (m_type == CLTYPE::VERTEX) {
ends = calcEndPoints2Points(partFeat,
m_verts,
m_mode,
m_extendBy,
m_hShift, m_vShift, m_rotate, m_flip2Line);
try {
if (m_type == CLTYPE::FACE) {
ends = calcEndPoints(partFeat,
m_faces,
m_mode, m_extendBy,
m_hShift,m_vShift, m_rotate);
} else if (m_type == CLTYPE::EDGE) {
ends = calcEndPoints2Lines(partFeat,
m_edges,
m_mode,
m_extendBy,
m_hShift, m_vShift, m_rotate, m_flip2Line);
} else if (m_type == CLTYPE::VERTEX) {
ends = calcEndPoints2Points(partFeat,
m_verts,
m_mode,
m_extendBy,
m_hShift, m_vShift, m_rotate, m_flip2Line);
}
}

catch (...) {
Base::Console().Error("CL::scaledGeometry - failed to calculate endpoints!\n");
return nullptr;
}

TechDraw::BaseGeom* newGeom = nullptr;
Base::Vector3d p1 = ends.first;
Base::Vector3d p2 = ends.second;
Expand All @@ -748,6 +767,8 @@ TechDraw::BaseGeom* CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFeat)
newGeom->classOfEdge = ecHARD;
newGeom->hlrVisible = true;
newGeom->cosmetic = true;
newGeom->source(CENTERLINE);
newGeom->setCosmeticTag(getTagAsString());
return newGeom;
}

Expand Down Expand Up @@ -794,10 +815,10 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints(DrawViewPart
double hShift, double vShift,
double rotate)
{
Base::Console().Message("CL::calcEndPoints()\n");
// Base::Console().Message("CL::calcEndPoints()\n");
std::pair<Base::Vector3d, Base::Vector3d> result;
if (faceNames.empty()) {
Base::Console().Message("CL::calcEndPoints - no faces!\n");
Base::Console().Warning("CL::calcEndPoints - no faces!\n");
return result;
}

Expand All @@ -813,16 +834,19 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints(DrawViewPart
int idx = TechDraw::DrawUtil::getIndexFromName(fn);
std::vector<TechDraw::BaseGeom*> faceEdges =
partFeat->getFaceEdgesByIndex(idx);
for (auto& fe: faceEdges) {
if (!fe->cosmetic) {
BRepBndLib::Add(fe->occEdge, faceBox);
if (!faceEdges.empty()) {
for (auto& fe: faceEdges) {
if (!fe->cosmetic) {
BRepBndLib::Add(fe->occEdge, faceBox);
}
}
}
}

if (faceBox.IsVoid()) {
Base::Console().Error("CL::calcEndPoints - faceBox is void!\n");
return result;
// return result;
throw Base::IndexError("CenterLine wrong number of faces.");
}

double Xmin,Ymin,Zmin,Xmax,Ymax,Zmax;
Expand Down Expand Up @@ -897,10 +921,10 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
double rotate, bool flip)

{
Base::Console().Message("CL::calc2Lines() - mode: %d flip: %d\n", mode, flip);
// Base::Console().Message("CL::calc2Lines() - mode: %d flip: %d\n", mode, flip);
std::pair<Base::Vector3d, Base::Vector3d> result;
if (edgeNames.empty()) {
Base::Console().Message("CL::calcEndPoints2Lines - no edges!\n");
Base::Console().Warning("CL::calcEndPoints2Lines - no edges!\n");
return result;
}

Expand All @@ -913,11 +937,14 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
}
int idx = TechDraw::DrawUtil::getIndexFromName(en);
TechDraw::BaseGeom* bg = partFeat->getGeomByIndex(idx);
edges.push_back(bg);
if (bg != nullptr) {
edges.push_back(bg);
}
}
if (edges.size() != 2) {
Base::Console().Message("CL::calcEndPoints2Lines - wrong number of edges!\n");
return result;
// Base::Console().Message("CL::calcEndPoints2Lines - wrong number of edges!\n");
// return result;
throw Base::IndexError("CenterLine wrong number of edges.");
}

Base::Vector3d l1p1 = edges.front()->getStartPoint();
Expand Down Expand Up @@ -992,10 +1019,10 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Points(DrawV
double rotate, bool flip)

{
Base::Console().Message("CL::calc2Points()\n");
// Base::Console().Message("CL::calc2Points()\n");
std::pair<Base::Vector3d, Base::Vector3d> result;
if (vertNames.empty()) {
Base::Console().Message("CL::calcEndPoints2Points - no points!\n");
Base::Console().Warning("CL::calcEndPoints2Points - no points!\n");
return result;
}

Expand All @@ -1008,11 +1035,15 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Points(DrawV
}
int idx = TechDraw::DrawUtil::getIndexFromName(vn);
TechDraw::Vertex* v = partFeat->getProjVertexByIndex(idx);
points.push_back(v);
if (v != nullptr) {
points.push_back(v);
}
}
if (points.size() != 2) {
Base::Console().Message("CL::calcEndPoints2Points - wrong number of points!\n");
return result;
//this should fail harder. maybe be in a try/catch.
// Base::Console().Message("CL::calcEndPoints2Points - wrong number of points!\n");
// return result;
throw Base::IndexError("CenterLine wrong number of points.");
}

Base::Vector3d v1 = points.front()->point();
Expand Down Expand Up @@ -1140,18 +1171,18 @@ void CenterLine::Save(Base::Writer &writer) const

writer.Stream()
<< writer.ind()
<< "<Points "
<< "PointCount=\"" << m_verts.size() <<
<< "<CLPoints "
<< "CLPointCount=\"" << m_verts.size() <<
"\">" << endl;

writer.incInd();
for (auto& p: m_verts) {
writer.Stream()
<< writer.ind()
<< "<Point value=\"" << p <<"\"/>" << endl;
<< "<CLPoint value=\"" << p <<"\"/>" << endl;
}
writer.decInd();
writer.Stream() << writer.ind() << "</Points>" << endl ;
writer.Stream() << writer.ind() << "</CLPoints>" << endl ;

writer.Stream() << writer.ind() << "<Style value=\"" << m_format.m_style << "\"/>" << endl;
writer.Stream() << writer.ind() << "<Weight value=\"" << m_format.m_weight << "\"/>" << endl;
Expand All @@ -1160,20 +1191,24 @@ void CenterLine::Save(Base::Writer &writer) const
writer.Stream() << writer.ind() << "<Visible value=\"" << v << "\"/>" << endl;

//stored geometry
writer.Stream() << writer.ind() << "<GeometryType value=\"" << m_geometry->geomType <<"\"/>" << endl;
if (m_geometry->geomType == TechDraw::GeomType::GENERIC) {
Generic* gen = static_cast<Generic*>(m_geometry);
gen->Save(writer);
} else if (m_geometry->geomType == TechDraw::GeomType::CIRCLE) {
TechDraw::Circle* circ = static_cast<TechDraw::Circle*>(m_geometry);
circ->Save(writer);
} else if (m_geometry->geomType == TechDraw::GeomType::ARCOFCIRCLE) {
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*>(m_geometry);
aoc->Save(writer);
if (m_geometry != nullptr) {
writer.Stream() << writer.ind() << "<GeometryType value=\"" << m_geometry->geomType <<"\"/>" << endl;
if (m_geometry->geomType == TechDraw::GeomType::GENERIC) {
Generic* gen = static_cast<Generic*>(m_geometry);
gen->Save(writer);
} else if (m_geometry->geomType == TechDraw::GeomType::CIRCLE) {
TechDraw::Circle* circ = static_cast<TechDraw::Circle*>(m_geometry);
circ->Save(writer);
} else if (m_geometry->geomType == TechDraw::GeomType::ARCOFCIRCLE) {
TechDraw::AOC* aoc = static_cast<TechDraw::AOC*>(m_geometry);
aoc->Save(writer);
} else {
Base::Console().Message("CL::Save - unimplemented geomType: %d\n", m_geometry->geomType);
}
} else {
Base::Console().Message("CE::Save - unimplemented geomType: %d\n", m_geometry->geomType);
Base::Console().Error("CL::Save - m_geometry is null\n");
//TODO: create a placeholder for missing geom???
}

}

void CenterLine::Restore(Base::XMLReader &reader)
Expand Down Expand Up @@ -1228,16 +1263,16 @@ void CenterLine::Restore(Base::XMLReader &reader)
}
reader.readEndElement("Edges");

reader.readElement("Points");
count = reader.getAttributeAsInteger("PointCount");
reader.readElement("CLPoints");
count = reader.getAttributeAsInteger("CLPointCount");

i = 0;
for ( ; i < count; i++) {
reader.readElement("Point");
reader.readElement("CLPoint");
std::string p = reader.getAttribute("value");
m_verts.push_back(p);
}
reader.readEndElement("Points");
reader.readEndElement("CLPoints");

reader.readElement("Style");
m_format.m_style = reader.getAttributeAsInteger("value");
Expand All @@ -1257,7 +1292,6 @@ void CenterLine::Restore(Base::XMLReader &reader)
gen->Restore(reader);
gen->occEdge = GeometryUtils::edgeFromGeneric(gen);
m_geometry = (TechDraw::BaseGeom*) gen;

} else if (gType == TechDraw::GeomType::CIRCLE) {
TechDraw::Circle* circ = new TechDraw::Circle();
circ->Restore(reader);
Expand All @@ -1269,9 +1303,8 @@ void CenterLine::Restore(Base::XMLReader &reader)
aoc->occEdge = GeometryUtils::edgeFromCircleArc(aoc);
m_geometry = (TechDraw::BaseGeom*) aoc;
} else {
Base::Console().Message("CE::Restore - unimplemented geomType: %d\n", gType);
}

Base::Console().Warning("CL::Restore - unimplemented geomType: %d\n", gType);
}
}

CenterLine* CenterLine::copy(void) const
Expand All @@ -1290,11 +1323,12 @@ CenterLine* CenterLine::copy(void) const
newCL->m_faces = m_faces;
newCL->m_edges = m_edges;
newCL->m_verts = m_verts;

TechDraw::BaseGeom* newGeom = m_geometry->copy();
newCL->m_geometry = newGeom;

newCL->m_format = m_format;

newCL->m_format.m_style = m_format.m_style;
newCL->m_format.m_weight = m_format.m_weight;
newCL->m_format.m_color = m_format.m_color;
newCL->m_format.m_visible = m_format.m_visible;
return newCL;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Mod/TechDraw/App/Cosmetic.h
Expand Up @@ -177,7 +177,6 @@ class TechDrawExport CenterLine: public Base::Persistence
VERTEX
};


// Persistence implementer ---------------------
virtual unsigned int getMemSize(void) const;
virtual void Save(Base::Writer &/*writer*/) const;
Expand Down Expand Up @@ -244,6 +243,8 @@ class TechDrawExport CenterLine: public Base::Persistence
virtual std::string getTagAsString(void) const;

protected:
void initialize();

void createNewTag();
void assignTag(const TechDraw::CenterLine* cl);

Expand Down Expand Up @@ -274,7 +275,7 @@ class TechDrawExport GeomFormat: public Base::Persistence
std::string toString(void) const;
void dump(char* title) const;

int m_geomIndex;
int m_geomIndex;
LineFormat m_format;

//Uniqueness
Expand Down

0 comments on commit fcf5435

Please sign in to comment.