[TechDraw] Improve readability of DrawGeomHatch.cpp
This commit is contained in:
committed by
WandererFan
parent
8dcbd7080e
commit
5da15d23cf
@@ -176,8 +176,8 @@ void DrawGeomHatch::unsetupObject()
|
||||
void DrawGeomHatch::makeLineSets()
|
||||
{
|
||||
// Base::Console().Message("DGH::makeLineSets()\n");
|
||||
if ((!PatIncluded.isEmpty()) &&
|
||||
(!NamePattern.isEmpty())) {
|
||||
if (!PatIncluded.isEmpty() &&
|
||||
!NamePattern.isEmpty()) {
|
||||
m_lineSets.clear();
|
||||
m_lineSets = makeLineSets(PatIncluded.getValue(),
|
||||
NamePattern.getValue());
|
||||
@@ -188,17 +188,18 @@ void DrawGeomHatch::makeLineSets()
|
||||
std::vector<LineSet> DrawGeomHatch::makeLineSets(std::string fileSpec, std::string myPattern)
|
||||
{
|
||||
std::vector<LineSet> lineSets;
|
||||
if (!fileSpec.empty() &&
|
||||
!myPattern.empty()) {
|
||||
std::vector<PATLineSpec> specs =
|
||||
DrawGeomHatch::getDecodedSpecsFromFile(fileSpec,
|
||||
myPattern);
|
||||
for (auto& hl: specs) {
|
||||
//hl.dump("hl from section");
|
||||
LineSet ls;
|
||||
ls.setPATLineSpec(hl);
|
||||
lineSets.push_back(ls);
|
||||
}
|
||||
if (fileSpec.empty() && myPattern.empty()) {
|
||||
return lineSets;
|
||||
}
|
||||
|
||||
std::vector<PATLineSpec> specs =
|
||||
DrawGeomHatch::getDecodedSpecsFromFile(fileSpec,
|
||||
myPattern);
|
||||
for (auto& hl: specs) {
|
||||
//hl.dump("hl from section");
|
||||
LineSet ls;
|
||||
ls.setPATLineSpec(hl);
|
||||
lineSets.push_back(ls);
|
||||
}
|
||||
return lineSets;
|
||||
}
|
||||
@@ -222,15 +223,12 @@ std::vector<PATLineSpec> DrawGeomHatch::getDecodedSpecsFromFile()
|
||||
/*static*/
|
||||
std::vector<PATLineSpec> DrawGeomHatch::getDecodedSpecsFromFile(std::string fileSpec, std::string myPattern)
|
||||
{
|
||||
std::vector<PATLineSpec> result;
|
||||
Base::FileInfo fi(fileSpec);
|
||||
if (!fi.isReadable()) {
|
||||
Base::Console().Error("DrawGeomHatch::getDecodedSpecsFromFile not able to open %s!\n", fileSpec.c_str());
|
||||
return result;
|
||||
return std::vector<PATLineSpec>();
|
||||
}
|
||||
result = PATLineSpec::getSpecsForPattern(fileSpec, myPattern);
|
||||
|
||||
return result;
|
||||
return PATLineSpec::getSpecsForPattern(fileSpec, myPattern);
|
||||
}
|
||||
|
||||
std::vector<LineSet> DrawGeomHatch::getTrimmedLines(int i) //get the trimmed hatch lines for face i
|
||||
@@ -239,11 +237,10 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLines(int i) //get the trimmed
|
||||
makeLineSets();
|
||||
}
|
||||
|
||||
std::vector<LineSet> result;
|
||||
DrawViewPart* source = getSourceView();
|
||||
if (!source ||
|
||||
!source->hasGeometry()) {
|
||||
return result;
|
||||
return std::vector<LineSet>();
|
||||
}
|
||||
return getTrimmedLines(source, m_lineSets, i, ScalePattern.getValue(),
|
||||
PatternRotation.getValue(), PatternOffset.getValue());
|
||||
@@ -273,13 +270,14 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLinesSection(DrawViewSection* sou
|
||||
TopoDS_Shape moved = TechDraw::moveShape(f,
|
||||
offset);
|
||||
TopoDS_Face fMoved = TopoDS::Face(GeometryObject::invertGeometry(moved));
|
||||
result = getTrimmedLines(source,
|
||||
lineSets,
|
||||
fMoved,
|
||||
scale,
|
||||
hatchRotation,
|
||||
hatchOffset );
|
||||
return result;
|
||||
return getTrimmedLines(
|
||||
source,
|
||||
lineSets,
|
||||
fMoved,
|
||||
scale,
|
||||
hatchRotation,
|
||||
hatchOffset
|
||||
);
|
||||
}
|
||||
|
||||
//! get hatch lines trimmed to face outline
|
||||
@@ -288,13 +286,14 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLines(DrawViewPart* source, std::v
|
||||
Base::Vector3d hatchOffset)
|
||||
{
|
||||
TopoDS_Face face = extractFace(source, iface);
|
||||
std::vector<LineSet> result = getTrimmedLines(source,
|
||||
lineSets,
|
||||
face,
|
||||
scale,
|
||||
hatchRotation,
|
||||
hatchOffset );
|
||||
return result;
|
||||
return getTrimmedLines(
|
||||
source,
|
||||
lineSets,
|
||||
face,
|
||||
scale,
|
||||
hatchRotation,
|
||||
hatchOffset
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<LineSet> DrawGeomHatch::getTrimmedLines(DrawViewPart* source,
|
||||
@@ -346,8 +345,8 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLines(DrawViewPart* source,
|
||||
|
||||
//Common(Compound, Face)
|
||||
BRepAlgoAPI_Common mkCommon(face, grid);
|
||||
if ((!mkCommon.IsDone()) ||
|
||||
(mkCommon.Shape().IsNull()) ) {
|
||||
if (!mkCommon.IsDone() ||
|
||||
mkCommon.Shape().IsNull()) {
|
||||
return result;
|
||||
}
|
||||
TopoDS_Shape common = mkCommon.Shape();
|
||||
@@ -431,8 +430,8 @@ std::vector<TopoDS_Edge> DrawGeomHatch::makeEdgeOverlay(PATLineSpec hl, Bnd_Box
|
||||
TopoDS_Edge newLine = makeLine(newStart, newEnd);
|
||||
result.push_back(newLine);
|
||||
}
|
||||
} else if ((angle == 90.0) ||
|
||||
(angle == -90.0)) { //odd case 2: vertical lines
|
||||
} else if (angle == 90.0 ||
|
||||
angle == -90.0) { //odd case 2: vertical lines
|
||||
interval = hl.getInterval() * scale;
|
||||
double atomX = origin.x;
|
||||
int repeatRight = (int) fabs((maxX - atomX)/interval);
|
||||
@@ -493,14 +492,12 @@ std::vector<TopoDS_Edge> DrawGeomHatch::makeEdgeOverlay(PATLineSpec hl, Bnd_Box
|
||||
|
||||
TopoDS_Edge DrawGeomHatch::makeLine(Base::Vector3d s, Base::Vector3d e)
|
||||
{
|
||||
TopoDS_Edge result;
|
||||
gp_Pnt start(s.x, s.y, 0.0);
|
||||
gp_Pnt end(e.x, e.y, 0.0);
|
||||
TopoDS_Vertex v1 = BRepBuilderAPI_MakeVertex(start);
|
||||
TopoDS_Vertex v2 = BRepBuilderAPI_MakeVertex(end);
|
||||
BRepBuilderAPI_MakeEdge makeEdge1(v1, v2);
|
||||
result = makeEdge1.Edge();
|
||||
return result;
|
||||
return makeEdge1.Edge();
|
||||
}
|
||||
|
||||
//! get all the untrimmed hatchlines for a face
|
||||
@@ -549,8 +546,6 @@ std::vector<LineSet> DrawGeomHatch::getFaceOverlay(int fdx)
|
||||
//! TODO: DVP can serve these up ready to use
|
||||
TopoDS_Face DrawGeomHatch::extractFace(DrawViewPart* source, int iface )
|
||||
{
|
||||
TopoDS_Face result;
|
||||
|
||||
std::vector<TopoDS_Wire> faceWires = source->getWireForFace(iface);
|
||||
|
||||
//build face(s) from geometry
|
||||
@@ -564,7 +559,7 @@ TopoDS_Face DrawGeomHatch::extractFace(DrawViewPart* source, int iface )
|
||||
mkFace.Add(*itWire);
|
||||
}
|
||||
if (!mkFace.IsDone()) {
|
||||
return result;
|
||||
return TopoDS_Face();
|
||||
}
|
||||
TopoDS_Face face = mkFace.Face();
|
||||
|
||||
@@ -577,10 +572,9 @@ TopoDS_Face DrawGeomHatch::extractFace(DrawViewPart* source, int iface )
|
||||
temp = mkTrf.Shape();
|
||||
}
|
||||
catch (...) {
|
||||
return result;
|
||||
return TopoDS_Face();
|
||||
}
|
||||
result = TopoDS::Face(temp);
|
||||
return result;
|
||||
return TopoDS::Face(temp);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -605,7 +599,7 @@ std::string DrawGeomHatch::prefGeomHatchName()
|
||||
std::string defaultNamePattern = "Diamond";
|
||||
std::string result = hGrp->GetASCII("NamePattern", defaultNamePattern.c_str());
|
||||
if (result.empty()) {
|
||||
result = defaultNamePattern;
|
||||
return defaultNamePattern;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user