| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| |
|
| | # include <iomanip>
|
| | # include <sstream>
|
| |
|
| |
|
| | #include <App/Application.h>
|
| | #include <App/Document.h>
|
| | #include <Base/Console.h>
|
| | #include <Base/FileInfo.h>
|
| | #include <Base/Parameter.h>
|
| |
|
| | #include "DrawHatch.h"
|
| | #include "DrawHatchPy.h"
|
| | #include "DrawUtil.h"
|
| | #include "DrawViewPart.h"
|
| | #include "Preferences.h"
|
| |
|
| |
|
| | using namespace TechDraw;
|
| | using DU = DrawUtil;
|
| |
|
| | PROPERTY_SOURCE(TechDraw::DrawHatch, App::DocumentObject)
|
| |
|
| | DrawHatch::DrawHatch(void)
|
| | {
|
| | static const char *vgroup = "Hatch";
|
| |
|
| | ADD_PROPERTY_TYPE(Source, (nullptr), vgroup, App::PropertyType::Prop_None, "The View + Face to be hatched");
|
| | Source.setScope(App::LinkScope::Global);
|
| | ADD_PROPERTY_TYPE(HatchPattern, (prefSvgHatch()), vgroup, App::Prop_None, "The hatch pattern file for this area");
|
| | ADD_PROPERTY_TYPE(SvgIncluded, (""), vgroup, App::Prop_None,
|
| | "Embedded SVG hatch file. System use only.");
|
| | std::string svgFilter("SVG files (*.svg *.SVG);;Bitmap files(*.jpg *.jpeg *.png *.bmp);;All files (*)");
|
| | HatchPattern.setFilter(svgFilter);
|
| | }
|
| |
|
| | void DrawHatch::onChanged(const App::Property* prop)
|
| | {
|
| | if (isRestoring()) {
|
| | App::DocumentObject::onChanged(prop);
|
| | return;
|
| | }
|
| |
|
| | if (prop == &HatchPattern) {
|
| | replaceFileIncluded(HatchPattern.getValue());
|
| | }
|
| | App::DocumentObject::onChanged(prop);
|
| | }
|
| |
|
| | App::DocumentObjectExecReturn *DrawHatch::execute(void)
|
| | {
|
| | DrawViewPart* parent = getSourceView();
|
| | if (parent) {
|
| | parent->requestPaint();
|
| | }
|
| | return App::DocumentObject::StdReturn;
|
| | }
|
| |
|
| | DrawViewPart* DrawHatch::getSourceView(void) const
|
| | {
|
| | App::DocumentObject* obj = Source.getValue();
|
| | DrawViewPart* result = freecad_cast<DrawViewPart*>(obj);
|
| | return result;
|
| | }
|
| |
|
| | PyObject *DrawHatch::getPyObject(void)
|
| | {
|
| | if (PythonObject.is(Py::_None())) {
|
| |
|
| | PythonObject = Py::Object(new DrawHatchPy(this), true);
|
| | }
|
| | return Py::new_reference_to(PythonObject);
|
| | }
|
| |
|
| | bool DrawHatch::faceIsHatched(int i, std::vector<TechDraw::DrawHatch*> hatchObjs)
|
| | {
|
| | 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) {
|
| | return true;
|
| | }
|
| | }
|
| | }
|
| | return false;
|
| | }
|
| |
|
| |
|
| | bool DrawHatch::affectsFace(int i)
|
| | {
|
| | const std::vector<std::string> &sourceNames = Source.getSubValues();
|
| | for (auto& s : sourceNames) {
|
| | int fdx = TechDraw::DrawUtil::getIndexFromName(s);
|
| | if (fdx == i) {
|
| | return true;
|
| | }
|
| | }
|
| | return false;
|
| | }
|
| |
|
| |
|
| | bool DrawHatch::removeSub(std::string toRemove)
|
| | {
|
| |
|
| | 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)
|
| | {
|
| |
|
| | 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();
|
| | }
|
| |
|
| | void DrawHatch::replaceFileIncluded(std::string newHatchFileName)
|
| | {
|
| |
|
| | if (newHatchFileName.empty()) {
|
| | return;
|
| | }
|
| |
|
| | Base::FileInfo tfi(newHatchFileName);
|
| | if (tfi.isReadable()) {
|
| | SvgIncluded.setValue(newHatchFileName.c_str());
|
| | } else {
|
| | throw Base::RuntimeError("Could not read the new svg file");
|
| | }
|
| | }
|
| |
|
| | void DrawHatch::setupObject()
|
| | {
|
| |
|
| | replaceFileIncluded(HatchPattern.getValue());
|
| | }
|
| |
|
| | void DrawHatch::unsetupObject(void)
|
| | {
|
| |
|
| | App::DocumentObject* source = Source.getValue();
|
| | DrawView* dv = freecad_cast<DrawView*>(source);
|
| | if (dv) {
|
| | dv->requestPaint();
|
| | }
|
| | App::DocumentObject::unsetupObject();
|
| | }
|
| |
|
| | bool DrawHatch::isSvgHatch(void) const
|
| | {
|
| | Base::FileInfo fi(HatchPattern.getValue());
|
| | return fi.hasExtension("svg");
|
| | }
|
| |
|
| | bool DrawHatch::isBitmapHatch(void) const
|
| | {
|
| | Base::FileInfo fi(HatchPattern.getValue());
|
| | return fi.hasExtension({"bmp", "png", "jpg", "jpeg"});
|
| | }
|
| |
|
| |
|
| |
|
| | void DrawHatch::translateLabel(std::string context, std::string baseName, std::string uniqueName)
|
| | {
|
| | Label.setValue(DU::translateArbitrary(context, baseName, uniqueName));
|
| | }
|
| |
|
| |
|
| | std::string DrawHatch::prefSvgHatch(void)
|
| | {
|
| | return Preferences::svgFile();
|
| | }
|
| |
|
| | Base::Color DrawHatch::prefSvgHatchColor(void)
|
| | {
|
| | Base::Color fcColor;
|
| | fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("Hatch", 0x00FF0000));
|
| | return fcColor;
|
| | }
|
| |
|
| |
|
| |
|
| | namespace App {
|
| |
|
| | PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawHatchPython, TechDraw::DrawHatch)
|
| | template<> const char* TechDraw::DrawHatchPython::getViewProviderName(void) const {
|
| | return "TechDrawGui::ViewProviderHatch";
|
| | }
|
| |
|
| |
|
| |
|
| | template class TechDrawExport FeaturePythonT<TechDraw::DrawHatch>;
|
| | }
|
| |
|