Allow hatching of section face

This commit is contained in:
WandererFan 2016-10-05 13:53:18 -04:00 committed by Yorik van Havre
parent 10e03f6c64
commit 2f6a779205
3 changed files with 51 additions and 8 deletions

View File

@ -56,6 +56,9 @@
#include <chrono>
# include <QFile>
# include <QFileInfo>
#include <App/Application.h>
#include <App/Material.h>
#include <Base/BoundBox.h>
@ -85,16 +88,20 @@ DrawViewSection::DrawViewSection()
static const char *fgroup = "Format";
//static const char *lgroup = "Line";
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("CutSurfaceColor", 0xC8C8C800));
ADD_PROPERTY_TYPE(BaseView ,(0),sgroup,App::Prop_None,"2D View with SectionLine");
ADD_PROPERTY_TYPE(SectionNormal ,(0,0,1.0) ,sgroup,App::Prop_None,"Section Plane normal direction"); //direction of extrusion of cutting prism
ADD_PROPERTY_TYPE(SectionNormal ,(0,0,1.0) ,sgroup,App::Prop_None,"Section Plane normal direction"); //direction of extrusion of cutting prism
ADD_PROPERTY_TYPE(SectionOrigin ,(0,0,0) ,sgroup,App::Prop_None,"Section Plane Origin");
ADD_PROPERTY_TYPE(ShowCutSurface ,(true),fgroup,App::Prop_None,"Show the cut surface");
ADD_PROPERTY_TYPE(CutSurfaceColor,(fcColor),fgroup,App::Prop_None,"The color to shade the cut surface");
ADD_PROPERTY_TYPE(ShowCutSurface ,(true),fgroup,App::Prop_None,"Shade the cut surface");
ADD_PROPERTY_TYPE(CutSurfaceColor,(0.0,0.0,0.0),fgroup,App::Prop_None,"The color to shade the cut surface");
ADD_PROPERTY_TYPE(HatchCutSurface ,(false),fgroup,App::Prop_None,"Hatch the cut surface");
ADD_PROPERTY_TYPE(HatchPattern ,(""),fgroup,App::Prop_None,"The hatch pattern file for the cut surface");
ADD_PROPERTY_TYPE(HatchColor,(0.0,0.0,0.0),fgroup,App::Prop_None,"The color of the hatch pattern");
getParameters();
}
DrawViewSection::~DrawViewSection()
@ -439,6 +446,30 @@ bool DrawViewSection::isReallyInBox (const Base::Vector3d v, const Base::BoundBo
return true;
}
void DrawViewSection::getParameters()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors");
App::Color cutColor = App::Color((uint32_t) hGrp->GetUnsigned("CutSurfaceColor", 0xC8C8C800));
CutSurfaceColor.setValue(cutColor);
App::Color hatchColor = App::Color((uint32_t) hGrp->GetUnsigned("SectionHatchColor", 0x00000000));
HatchColor.setValue(hatchColor);
hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw");
std::string defaultDir = App::Application::getResourceDir() + "Mod/Drawing/patterns/";
std::string defaultFileName = defaultDir + "simple.svg";
QString patternFileName = QString::fromStdString(hGrp->GetASCII("PatternFile",defaultFileName.c_str()));
if (patternFileName.isEmpty()) {
patternFileName = QString::fromStdString(defaultFileName);
}
QFileInfo tfi(patternFileName);
if (tfi.isReadable()) {
HatchPattern.setValue(patternFileName.toUtf8().constData());
}
}
// Python Drawing feature ---------------------------------------------------------

View File

@ -26,7 +26,9 @@
#include <App/DocumentObject.h>
#include <App/PropertyLinks.h>
#include <App/PropertyFile.h>
#include <App/FeaturePython.h>
#include <App/Material.h>
#include <TopoDS_Compound.hxx>
@ -60,6 +62,10 @@ public:
App::PropertyVector SectionOrigin;
App::PropertyBool ShowCutSurface;
App::PropertyColor CutSurfaceColor;
App::PropertyBool HatchCutSurface;
App::PropertyFile HatchPattern;
App::PropertyColor HatchColor;
virtual short mustExecute() const;
bool isReallyInBox (const Base::Vector3d v, const Base::BoundBox3d bb) const;
@ -87,6 +93,7 @@ protected:
gp_Pnt faceCenter,
const Base::Vector3d &direction,
const Base::Vector3d &xaxis);
void getParameters(void);
};
typedef App::FeaturePythonT<DrawViewSection> DrawViewSectionPython;

View File

@ -76,14 +76,19 @@ void QGIViewSection::drawSectionFace()
std::vector<TechDrawGeometry::Face *>::iterator fit = sectionFaces.begin();
QColor faceColor = section->CutSurfaceColor.getValue().asValue<QColor>();
for(; fit != sectionFaces.end(); fit++) {
QGIFace* newFace = drawFace(*fit,-1); //TODO: do we need to know which sectionFace this QGIFace came from?
QGIFace* newFace = drawFace(*fit,-1);
newFace->setZValue(ZVALUE::SECTIONFACE);
newFace->setFill(faceColor, Qt::SolidPattern);
if (section->showSectionEdges()) {
newFace->setDrawEdges(true);
} else {
newFace->setDrawEdges(false);
}
if (section->HatchCutSurface.getValue()) {
App::Color hColor = section->HatchColor.getValue();
newFace->setHatchColor(hColor.asCSSString());
newFace->setHatch(section->HatchPattern.getValue());
}
newFace->setFill(faceColor, Qt::SolidPattern);
newFace->setPrettyNormal();
newFace->setAcceptHoverEvents(false);
newFace->setFlag(QGraphicsItem::ItemIsSelectable, false);