diff --git a/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp b/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp index 237e4e31cc..c0b1b27bd6 100644 --- a/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp +++ b/src/Mod/TechDraw/App/DrawViewSpreadsheet.cpp @@ -69,7 +69,6 @@ DrawViewSpreadsheet::DrawViewSpreadsheet(void) ADD_PROPERTY_TYPE(TextColor,(0.0f,0.0f,0.0f),vgroup,App::Prop_None,"The default color of the text and lines"); ADD_PROPERTY_TYPE(TextSize,(12.0),vgroup,App::Prop_None,"The size of the text"); ADD_PROPERTY_TYPE(LineWidth,(0.35),vgroup,App::Prop_None,"The thickness of the cell lines"); - //ADD_PROPERTY_TYPE(Symbol,(""),vgroup,App::Prop_Hidden,"The SVG image of this spreadsheet"); EditableTexts.setStatus(App::Property::Hidden,true); @@ -79,24 +78,26 @@ DrawViewSpreadsheet::~DrawViewSpreadsheet() { } +short DrawViewSpreadsheet::mustExecute() const +{ + short result = 0; + if (!isRestoring()) { + result = (Source.isTouched() || + CellStart.isTouched() || + CellEnd.isTouched() || + Font.isTouched() || + TextSize.isTouched() || + TextColor.isTouched() || + LineWidth.isTouched() ); + } + if (result) { + return result; + } + return TechDraw::DrawView::mustExecute(); +} + void DrawViewSpreadsheet::onChanged(const App::Property* prop) { - if (!isRestoring()) { - if (prop == &Source || - prop == &CellStart || - prop == &CellEnd || - prop == &Font || - prop == &TextSize || - prop == &TextColor || - prop == &LineWidth) { - try { - App::DocumentObjectExecReturn *ret = recompute(); - delete ret; - } - catch (...) { - } - } - } TechDraw::DrawView::onChanged(prop); } @@ -114,7 +115,6 @@ App::DocumentObjectExecReturn *DrawViewSpreadsheet::execute(void) Symbol.setValue(getSheetImage()); - requestPaint(); return TechDraw::DrawView::execute(); } @@ -123,13 +123,13 @@ std::vector DrawViewSpreadsheet::getAvailColumns(void) // build a list of available columns: A, B, C, ... AA, AB, ... ZY, ZZ. std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; std::vector availcolumns; - for (int i=0; i<26; ++i) { + for (int i=0; i<26; ++i) { //A:Z std::stringstream s; s << alphabet[i]; availcolumns.push_back(s.str()); } - for (int i=0; i<26; ++i) { - for (int j=0; i<26; ++i) { + for (int i=0; i<26; ++i) { //AA:ZZ + for (int j=0; j<26; ++j) { std::stringstream s; s << alphabet[i] << alphabet[j]; availcolumns.push_back(s.str()); @@ -138,7 +138,6 @@ std::vector DrawViewSpreadsheet::getAvailColumns(void) return availcolumns; } -//note: newlines need to be double escaped for python, but single for C++ std::string DrawViewSpreadsheet::getSVGHead(void) { std::string head = std::string(" columns; std::vector rows; - try { - for (unsigned int i=0; i::const_iterator j = availcolumns.begin(); j != availcolumns.end(); ++j) { - if ( (*j) == startcol) { - if ( (*j) != endcol) { - valid = true; - } - } else { - if (valid) { - if ( (*j) == endcol) { - columns.push_back((*j)); - valid = false; - } else { - columns.push_back((*j)); - } - } - } - } - int endrow = std::atoi(scellend.substr(i,scellend.length()-1).c_str()); - for (int j=rows.back()+1; j<=endrow; ++j) { - rows.push_back(j); - } + } - // after the first digit there will be no letter any more - break; - } + //validate startCol in A:ZZ + int iStart = colInList(availcolumns,startCol); + if (iStart >= 0) { + columns.push_back(startCol); + rows.push_back(startRow); + } else { + Base::Console().Error("DVS - %s - start Column (%s) is invalid\n",getNameInDocument(),startCol.c_str()); + return result.str(); + } + //startCol is valid + + //break endcell contents into row & col parts + std::string endCol; + int endRow = -1; + for (unsigned int i=0; i endCol) || + (startRow > endRow) ) { + Base::Console().Error("DVS - %s - cell range is invalid\n",getNameInDocument()); return result.str(); } - // create the containing group + //fill the col/row name vectors + if (startCol != endCol) { + int i = iStart + 1; + for ( ; i < iEnd; i++) { + columns.push_back(availcolumns.at(i)); + } + columns.push_back(endCol); + } + int i = startRow + 1; + for (; i < endRow; i ++) { + rows.push_back(i); + } + rows.push_back(endRow); + + // create the Svg code std::string ViewName = Label.getValue(); result << getSVGHead(); @@ -224,6 +242,7 @@ std::string DrawViewSpreadsheet::getSheetImage(void) std::string celltext; Spreadsheet::Sheet* sheet = static_cast(link); std::vector skiplist; + for (std::vector::const_iterator col = columns.begin(); col != columns.end(); ++col) { // create a group for each column result << " " << endl; @@ -321,6 +340,18 @@ std::string DrawViewSpreadsheet::getSheetImage(void) result << getSVGTail(); return result.str(); + +} + +int DrawViewSpreadsheet::colInList(const std::vector& list, + const std::string& toFind) +{ + int result = -1; + auto match = std::find(std::begin(list), std::end(list), toFind); + if (match != std::end(list)) { + result = match - std::begin(list); + } + return result; } // Python Drawing feature --------------------------------------------------------- diff --git a/src/Mod/TechDraw/App/DrawViewSpreadsheet.h b/src/Mod/TechDraw/App/DrawViewSpreadsheet.h index 5502cbb915..6e6d8ae94c 100644 --- a/src/Mod/TechDraw/App/DrawViewSpreadsheet.h +++ b/src/Mod/TechDraw/App/DrawViewSpreadsheet.h @@ -56,6 +56,7 @@ public: virtual App::DocumentObjectExecReturn *execute(void); + virtual short mustExecute() const; std::string getSheetImage(void); virtual const char* getViewProviderName(void) const { @@ -67,6 +68,8 @@ protected: std::vector getAvailColumns(void); std::string getSVGHead(void); std::string getSVGTail(void); + int colInList(const std::vector& list, + const std::string& toFind); private: };