[TD]correct PropertyFileIncluded handling in Welding
This commit is contained in:
@@ -25,10 +25,14 @@
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Tools.h>
|
||||
|
||||
#include "DrawUtil.h"
|
||||
|
||||
@@ -52,6 +56,9 @@ DrawTileWeld::DrawTileWeld(void)
|
||||
ADD_PROPERTY_TYPE(RightText, (0), group, App::Prop_None, "Text RHS");
|
||||
ADD_PROPERTY_TYPE(CenterText, (0), group, App::Prop_None, "Text above Symbol");
|
||||
ADD_PROPERTY_TYPE(SymbolFile, (""), group, App::Prop_None, "Svg Symbol File");
|
||||
|
||||
SymbolFile.setStatus(App::Property::ReadOnly,true);
|
||||
|
||||
}
|
||||
|
||||
DrawTileWeld::~DrawTileWeld()
|
||||
@@ -78,6 +85,29 @@ App::DocumentObjectExecReturn *DrawTileWeld::execute(void)
|
||||
return DrawTile::execute();
|
||||
}
|
||||
|
||||
void DrawTileWeld::replaceSymbol(std::string newSymbolFile)
|
||||
{
|
||||
// Base::Console().Message("DTW::replaceSymbol(%s)\n", newSymbolFile.c_str());
|
||||
std::string special = getNameInDocument();
|
||||
special += "Symbol.svg";
|
||||
std::string tempName = SymbolFile.getExchangeTempFile();
|
||||
copyFile(newSymbolFile, tempName);
|
||||
SymbolFile.setValue(tempName.c_str(), special.c_str());
|
||||
}
|
||||
|
||||
//copy whole text file from inSpec to outSpec
|
||||
void DrawTileWeld::copyFile(std::string inSpec, std::string outSpec)
|
||||
{
|
||||
// Base::Console().Message("DTW::copyFile(%s, %s)\n", inSpec.c_str(), outSpec.c_str());
|
||||
if (inSpec.empty()) {
|
||||
std::ofstream dst(outSpec); //make an empty file
|
||||
} else {
|
||||
std::ifstream src(inSpec);
|
||||
std::ofstream dst(outSpec);
|
||||
dst << src.rdbuf();
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *DrawTileWeld::getPyObject(void)
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#ifndef _TechDraw_DrawTileWeld_h_
|
||||
#define _TechDraw_DrawTileWeld_h_
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/FeaturePython.h>
|
||||
#include <App/PropertyFile.h>
|
||||
@@ -56,8 +58,11 @@ public:
|
||||
virtual PyObject *getPyObject(void);
|
||||
virtual QRectF getRect() const { return QRectF(0,0,1,1);}
|
||||
|
||||
void replaceSymbol(std::string newSymbolFile);
|
||||
|
||||
protected:
|
||||
virtual void onChanged(const App::Property* prop);
|
||||
void copyFile(std::string inSpec, std::string outSpec);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -62,13 +62,49 @@ DrawWeldSymbol::DrawWeldSymbol(void)
|
||||
Caption.setStatus(App::Property::Hidden,true);
|
||||
Scale.setStatus(App::Property::Hidden,true);
|
||||
ScaleType.setStatus(App::Property::Hidden,true);
|
||||
|
||||
}
|
||||
|
||||
DrawWeldSymbol::~DrawWeldSymbol()
|
||||
{
|
||||
}
|
||||
|
||||
//DWS always has exactly 2 child tiles - ArrowSide and OtherSide.
|
||||
//OtherSide tile may be hidden;
|
||||
//once DWS has been added to the document, add 2x DrawTileWeld
|
||||
//but if this is a restore of an existing DWS, the tiles will loaded elsewhere
|
||||
void DrawWeldSymbol::onSettingDocument()
|
||||
{
|
||||
// Base::Console().Message("DWS::onSettingDocument() - doc: %s\n", getDocument()->getName());
|
||||
App::Document* doc = getDocument();
|
||||
|
||||
if (doc->testStatus(App::Document::Status::Restoring)) {
|
||||
// Base::Console().Message("DWS::onSettingDocument() - restoring!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<DrawTileWeld*> existingTiles = getTiles();
|
||||
if (!existingTiles.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string tileName1 = doc->getUniqueObjectName("DrawTileWeld");
|
||||
auto tile1Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName1.c_str() ) );
|
||||
DrawTileWeld* tile1 = dynamic_cast<DrawTileWeld*>(tile1Obj);
|
||||
if (tile1 != nullptr) {
|
||||
tile1->TileParent.setValue(this);
|
||||
}
|
||||
|
||||
std::string tileName2 = doc->getUniqueObjectName("DrawTileWeld");
|
||||
auto tile2Obj( doc->addObject( "TechDraw::DrawTileWeld", tileName2.c_str() ) );
|
||||
DrawTileWeld* tile2 = dynamic_cast<DrawTileWeld*>(tile2Obj);
|
||||
if (tile2 != nullptr) {
|
||||
tile2->TileParent.setValue(this);
|
||||
}
|
||||
tile2->TileRow.setValue(-1); //other side is row -1
|
||||
|
||||
DrawView::onSettingDocument();
|
||||
}
|
||||
|
||||
void DrawWeldSymbol::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (!isRestoring()) {
|
||||
@@ -95,7 +131,6 @@ App::DocumentObjectExecReturn *DrawWeldSymbol::execute(void)
|
||||
std::vector<DrawTileWeld*> DrawWeldSymbol::getTiles(void) const
|
||||
{
|
||||
// Base::Console().Message("DWS::getTiles()\n");
|
||||
// std::vector<App::DocumentObject*> temp;
|
||||
std::vector<DrawTileWeld*> result;
|
||||
|
||||
std::vector<App::DocumentObject*> tiles = getInList();
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
|
||||
virtual short mustExecute() const;
|
||||
virtual App::DocumentObjectExecReturn *execute(void);
|
||||
virtual void onSettingDocument(void);
|
||||
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
return "TechDrawGui::ViewProviderWeld";
|
||||
|
||||
Reference in New Issue
Block a user