[TD]Remove old hatch on add new hatch

This commit is contained in:
wandererfan
2019-09-01 14:18:25 -04:00
committed by WandererFan
parent 830c8f866e
commit 5f4e9906a7
4 changed files with 150 additions and 14 deletions

View File

@@ -43,6 +43,7 @@
#include <Base/UnitsApi.h>
#include "DrawViewPart.h"
#include "DrawUtil.h"
#include "DrawHatch.h"
#include <Mod/TechDraw/App/DrawHatchPy.h> // generated from DrawHatchPy.xml
@@ -59,7 +60,7 @@ DrawHatch::DrawHatch(void)
ADD_PROPERTY_TYPE(DirProjection ,(0,0,1.0) ,vgroup,App::Prop_None,"Projection direction when Hatch was defined"); //sb RO?
ADD_PROPERTY_TYPE(Source,(0),vgroup,(App::PropertyType)(App::Prop_None),"The View + Face to be hatched");
Source.setScope(App::LinkScope::Global);
Source.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(HatchPattern ,(""),vgroup,App::Prop_None,"The hatch pattern file for this area");
DirProjection.setStatus(App::Property::ReadOnly,true);
@@ -119,6 +120,78 @@ PyObject *DrawHatch::getPyObject(void)
return Py::new_reference_to(PythonObject);
}
bool DrawHatch::faceIsHatched(int i,std::vector<TechDraw::DrawHatch*> hatchObjs)
{
bool result = false;
bool found = false;
for (auto& h:hatchObjs) {
const std::vector<std::string> &sourceNames = h->Source.getSubValues();
for (auto& s : sourceNames) {
int fdx = TechDraw::DrawUtil::getIndexFromName(s);
if (fdx == i) {
result = true;
found = true;
break;
}
}
if (found) {
break;
}
}
return result;
}
//does this hatch affect face i
bool DrawHatch::affectsFace(int i)
{
bool result = false;
const std::vector<std::string> &sourceNames = Source.getSubValues();
for (auto& s : sourceNames) {
int fdx = TechDraw::DrawUtil::getIndexFromName(s);
if (fdx == i) {
result = true;
break;
}
}
return result;
}
//remove a subElement(Face) from Source PropertyLinkSub
bool DrawHatch::removeSub(std::string toRemove)
{
// Base::Console().Message("DH::removeSub(%s)\n",toRemove.c_str());
bool removed = false;
const std::vector<std::string> &sourceNames = Source.getSubValues();
std::vector<std::string> newList;
App::DocumentObject* sourceFeat = Source.getValue();
for (auto& s: sourceNames) {
if (s == toRemove) {
removed = true;
} else {
newList.push_back(s);
}
}
if (removed) {
Source.setValue(sourceFeat, newList);
}
return removed;
}
bool DrawHatch::removeSub(int i)
{
// Base::Console().Message("DH::removeSub(%d)\n",i);
std::stringstream ss;
ss << "Face" << i;
return removeSub(ss.str());
}
bool DrawHatch::empty(void)
{
const std::vector<std::string> &sourceNames = Source.getSubValues();
return sourceNames.empty();
}
// Python Drawing feature ---------------------------------------------------------
namespace App {