Turned DrawUtil into class with static methods.
This commit is contained in:
parent
c6bcfd84ce
commit
898587454f
|
@ -41,15 +41,11 @@
|
|||
|
||||
#include "DrawUtil.h"
|
||||
|
||||
namespace DrawUtil {
|
||||
using namespace TechDraw;
|
||||
|
||||
//==============================================================================
|
||||
// convenient utility functions for TechDraw Module
|
||||
//==============================================================================
|
||||
extern "C" {
|
||||
int TechDrawExport getIndexFromName(std::string geomName)
|
||||
/*static*/ int DrawUtil::getIndexFromName(std::string geomName)
|
||||
{
|
||||
boost::regex re("\\d+$"); //one of more digits at end of string
|
||||
boost::regex re("\\d+$"); // one of more digits at end of string
|
||||
boost::match_results<std::string::const_iterator> what;
|
||||
boost::match_flag_type flags = boost::match_default;
|
||||
char* endChar;
|
||||
|
@ -69,7 +65,7 @@ int TechDrawExport getIndexFromName(std::string geomName)
|
|||
}
|
||||
}
|
||||
|
||||
std::string TechDrawExport getGeomTypeFromName(std::string geomName)
|
||||
std::string DrawUtil::getGeomTypeFromName(std::string geomName)
|
||||
{
|
||||
boost::regex re("^[a-zA-Z]*"); //one or more letters at start of string
|
||||
boost::match_results<std::string::const_iterator> what;
|
||||
|
@ -90,11 +86,10 @@ std::string TechDrawExport getGeomTypeFromName(std::string geomName)
|
|||
}
|
||||
}
|
||||
|
||||
std::string TechDrawExport makeGeomName(std::string geomType, int index)
|
||||
std::string DrawUtil::makeGeomName(std::string geomType, int index)
|
||||
{
|
||||
std::stringstream newName;
|
||||
newName << geomType << index;
|
||||
return newName.str();
|
||||
}
|
||||
} //end extern "C"
|
||||
} //end namespace DrawUtil
|
||||
|
||||
|
|
|
@ -23,13 +23,18 @@
|
|||
#ifndef _DrawUtil_h_
|
||||
#define _DrawUtil_h_
|
||||
|
||||
namespace DrawUtil {
|
||||
extern "C" {
|
||||
#include <string>
|
||||
|
||||
int getIndexFromName(std::string geomName);
|
||||
std::string getGeomTypeFromName(std::string geomName);
|
||||
std::string makeGeomName(std::string geomType, int index);
|
||||
namespace TechDraw
|
||||
{
|
||||
|
||||
} //end extern "C"
|
||||
} //end namespace DrawUtil
|
||||
/// Convenient utility functions for TechDraw Module
|
||||
class TechDrawExport DrawUtil {
|
||||
public:
|
||||
static int getIndexFromName(std::string geomName);
|
||||
static std::string getGeomTypeFromName(std::string geomName);
|
||||
static std::string makeGeomName(std::string geomType, int index);
|
||||
};
|
||||
|
||||
} //end namespace TechDraw
|
||||
#endif
|
||||
|
|
|
@ -959,8 +959,8 @@ int _isValidSingleEdge(Gui::Command* cmd) {
|
|||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
const std::vector<std::string> SubNames = selection[0].getSubNames();
|
||||
if (SubNames.size() == 1) { //only 1 subshape selected
|
||||
if (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge"
|
||||
int GeoId = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge"
|
||||
int GeoId( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) );
|
||||
TechDrawGeometry::BaseGeom* geom = objFeat->getProjEdgeByIndex(GeoId);
|
||||
if (!geom) {
|
||||
Base::Console().Error("Logic Error: no geometry for GeoId: %d\n",GeoId);
|
||||
|
@ -1000,8 +1000,8 @@ bool _isValidVertexes(Gui::Command* cmd) {
|
|||
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
const std::vector<std::string> SubNames = selection[0].getSubNames();
|
||||
if(SubNames.size() == 2) { //there are 2
|
||||
if (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" && //they both start with "Vertex"
|
||||
DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") {
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" && //they both start with "Vertex"
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1017,10 +1017,10 @@ int _isValidEdgeToEdge(Gui::Command* cmd) {
|
|||
//TechDraw::DrawViewPart* objFeat1 = dynamic_cast<TechDraw::DrawViewPart *>(selection[1].getObject());
|
||||
const std::vector<std::string> SubNames = selection[0].getSubNames();
|
||||
if(SubNames.size() == 2) { //there are 2
|
||||
if (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge"
|
||||
DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
|
||||
int GeoId0 = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
int GeoId1 = DrawUtil::getIndexFromName(SubNames[1]);
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge"
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
|
||||
int GeoId0( TechDraw::DrawUtil::getIndexFromName(SubNames[0]) );
|
||||
int GeoId1( TechDraw::DrawUtil::getIndexFromName(SubNames[1]) );
|
||||
TechDrawGeometry::BaseGeom* geom0 = objFeat0->getProjEdgeByIndex(GeoId0);
|
||||
TechDrawGeometry::BaseGeom* geom1 = objFeat0->getProjEdgeByIndex(GeoId1);
|
||||
if ((!geom0) || (!geom1)) {
|
||||
|
|
|
@ -361,8 +361,8 @@ void QGIViewDimension::draw()
|
|||
strcmp(dimType, "DistanceY") == 0) {
|
||||
Base::Vector3d distStart, distEnd;
|
||||
if((dim->References2D.getValues().size() == 1) &&
|
||||
(DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge")) {
|
||||
int idx = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
(TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge")) {
|
||||
int idx = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
|
||||
TechDrawGeometry::BaseGeom* geom = refObj->getProjEdgeByIndex(idx);
|
||||
if (!geom) {
|
||||
Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d of %d\n",
|
||||
|
@ -379,10 +379,10 @@ void QGIViewDimension::draw()
|
|||
throw Base::Exception("FVD::draw - Original edge not found or is invalid type (1)");
|
||||
}
|
||||
} else if(dim->References2D.getValues().size() == 2 &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") {
|
||||
int idx0 = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
int idx1 = DrawUtil::getIndexFromName(SubNames[1]);
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" &&
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Vertex") {
|
||||
int idx0 = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
|
||||
int idx1 = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
|
||||
TechDrawGeometry::Vertex *v0 = refObj->getProjVertexByIndex(idx0);
|
||||
TechDrawGeometry::Vertex *v1 = refObj->getProjVertexByIndex(idx1);
|
||||
if (!v0 || !v1) {
|
||||
|
@ -394,10 +394,10 @@ void QGIViewDimension::draw()
|
|||
distStart = Base::Vector3d (v0->pnt.fX, v0->pnt.fY, 0.);
|
||||
distEnd = Base::Vector3d (v1->pnt.fX, v1->pnt.fY, 0.);
|
||||
} else if(dim->References2D.getValues().size() == 2 &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
|
||||
int idx0 = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
int idx1 = DrawUtil::getIndexFromName(SubNames[1]);
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
|
||||
int idx0 = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
|
||||
int idx1 = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
|
||||
TechDrawGeometry::BaseGeom* geom0 = refObj->getProjEdgeByIndex(idx0);
|
||||
TechDrawGeometry::BaseGeom* geom1 = refObj->getProjEdgeByIndex(idx1);
|
||||
if (!geom0 || !geom1) {
|
||||
|
@ -600,8 +600,8 @@ void QGIViewDimension::draw()
|
|||
double radius;
|
||||
|
||||
if(dim->References2D.getValues().size() == 1 &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") {
|
||||
int idx = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") {
|
||||
int idx = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
|
||||
TechDrawGeometry::BaseGeom *geom = refObj->getProjEdgeByIndex(idx);
|
||||
if(!geom) {
|
||||
Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d of %d\n",
|
||||
|
@ -865,8 +865,8 @@ void QGIViewDimension::draw()
|
|||
Base::Vector3d pointOnCurve,curveCenter;
|
||||
double radius;
|
||||
if(dim->References2D.getValues().size() == 1 &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") {
|
||||
int idx = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") {
|
||||
int idx = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
|
||||
TechDrawGeometry::BaseGeom* geom = refObj->getProjEdgeByIndex(idx);
|
||||
if(!geom) {
|
||||
Base::Console().Log("INFO - qgivd::draw - no geom for projected edge: %d of %d\n",
|
||||
|
@ -975,10 +975,10 @@ void QGIViewDimension::draw()
|
|||
} else if(strcmp(dimType, "Angle") == 0) {
|
||||
// Only use two straight line edeges for angle
|
||||
if(dim->References2D.getValues().size() == 2 &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
|
||||
DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
|
||||
int idx0 = DrawUtil::getIndexFromName(SubNames[0]);
|
||||
int idx1 = DrawUtil::getIndexFromName(SubNames[1]);
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
|
||||
int idx0 = TechDraw::DrawUtil::getIndexFromName(SubNames[0]);
|
||||
int idx1 = TechDraw::DrawUtil::getIndexFromName(SubNames[1]);
|
||||
TechDrawGeometry::BaseGeom* geom0 = refObj->getProjEdgeByIndex(idx0);
|
||||
TechDrawGeometry::BaseGeom* geom1 = refObj->getProjEdgeByIndex(idx1);
|
||||
if (!geom0 || !geom1) {
|
||||
|
|
|
@ -320,7 +320,7 @@ void QGIViewPart::drawViewPart()
|
|||
|
||||
//get all edge geometries for this hatch
|
||||
for (; itEdge != edgeNames.end(); itEdge++) {
|
||||
int idxEdge = DrawUtil::getIndexFromName((*itEdge));
|
||||
int idxEdge = TechDraw::DrawUtil::getIndexFromName((*itEdge));
|
||||
TechDrawGeometry::BaseGeom* edgeGeom = viewPart->getProjEdgeByIndex(idxEdge);
|
||||
if (!edgeGeom) {
|
||||
Base::Console().Log("Error - qgivp::drawViewPart - edgeGeom: %d is NULL\n",idxEdge);
|
||||
|
|
|
@ -277,8 +277,8 @@ void ViewProviderPage::onSelectionChanged(const Gui::SelectionChanges& msg)
|
|||
std::string str = msg.pSubName;
|
||||
// If it's a subfeature, dont select feature
|
||||
if (!str.empty()) {
|
||||
if (DrawUtil::getGeomTypeFromName(str) == "Edge" ||
|
||||
DrawUtil::getGeomTypeFromName(str) == "Vertex") {
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(str) == "Edge" ||
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(str) == "Vertex") {
|
||||
//TODO: handle Faces
|
||||
// TODO implement me
|
||||
} else {
|
||||
|
@ -296,8 +296,8 @@ void ViewProviderPage::onSelectionChanged(const Gui::SelectionChanges& msg)
|
|||
std::string str = msg.pSubName;
|
||||
// If it's a subfeature, dont select feature
|
||||
if (!str.empty()) {
|
||||
if (DrawUtil::getGeomTypeFromName(str) == "Edge" ||
|
||||
DrawUtil::getGeomTypeFromName(str) == "Vertex") {
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(str) == "Edge" ||
|
||||
TechDraw::DrawUtil::getGeomTypeFromName(str) == "Vertex") {
|
||||
// TODO implement me
|
||||
} else {
|
||||
view->selectFeature(obj, selectState);
|
||||
|
|
Loading…
Reference in New Issue
Block a user