Allow True dimensions to reference multiple Parts

This commit is contained in:
WandererFan 2016-10-31 09:19:56 -04:00
parent 4eab324803
commit 256c5ed198
8 changed files with 131 additions and 66 deletions

View File

@ -85,6 +85,12 @@ bool Measurement::has3DReferences()
return (References3D.getSize() > 0); return (References3D.getSize() > 0);
} }
//add a 3D reference (obj+sub) to end of list
int Measurement::addReference3D(App::DocumentObject *obj, const std::string subName)
{
return addReference3D(obj,subName.c_str());
}
///add a 3D reference (obj+sub) to end of list ///add a 3D reference (obj+sub) to end of list
int Measurement::addReference3D(App::DocumentObject *obj, const char* subName) int Measurement::addReference3D(App::DocumentObject *obj, const char* subName)
{ {

View File

@ -58,6 +58,7 @@ public:
bool has3DReferences(); bool has3DReferences();
/// Add a reference /// Add a reference
int addReference3D(App::DocumentObject* obj, const std::string subName);
int addReference3D(App::DocumentObject* obj, const char *subName); int addReference3D(App::DocumentObject* obj, const char *subName);
MeasureType getType(); MeasureType getType();

View File

@ -140,7 +140,7 @@ void DrawViewDimension::onChanged(const App::Property* prop)
// MeasureType.getValue(),measurement->has3DReferences(),has3DReferences()); // MeasureType.getValue(),measurement->has3DReferences(),has3DReferences());
clear3DMeasurements(); //Measurement object clear3DMeasurements(); //Measurement object
if (!(References3D.getValues()).empty()) { if (!(References3D.getValues()).empty()) {
set3DMeasurement(References3D.getValues().at(0),References3D.getSubValues()); //Measurement object setAll3DMeasurement();
} else { } else {
if (MeasureType.isValue("True")) { //empty 3dRefs, but True if (MeasureType.isValue("True")) { //empty 3dRefs, but True
MeasureType.touch(); //run MeasureType logic for this case MeasureType.touch(); //run MeasureType logic for this case
@ -156,8 +156,7 @@ void DrawViewDimension::onChanged(const App::Property* prop)
void DrawViewDimension::onDocumentRestored() void DrawViewDimension::onDocumentRestored()
{ {
if (has3DReferences()) { if (has3DReferences()) {
clear3DMeasurements(); setAll3DMeasurement();
set3DMeasurement(References3D.getValues().at(0),References3D.getSubValues());
} }
} }
@ -254,6 +253,7 @@ double DrawViewDimension::getDimValue() const
if (!measurement->has3DReferences()) { if (!measurement->has3DReferences()) {
return result; return result;
} }
if(Type.isValue("Distance")) { if(Type.isValue("Distance")) {
result = measurement->delta().Length(); result = measurement->delta().Length();
} else if(Type.isValue("DistanceX")){ } else if(Type.isValue("DistanceX")){
@ -486,14 +486,17 @@ int DrawViewDimension::getRefType2(const std::string g1, const std::string g2)
return refType; return refType;
} }
//!add 1 3D measurement Reference //!add Dimension 3D references to measurement
void DrawViewDimension::set3DMeasurement(DocumentObject* const &obj, const std::vector<std::string>& subElements) void DrawViewDimension::setAll3DMeasurement()
{ {
std::vector<std::string>::const_iterator itSub = subElements.begin(); measurement->clear();
for (; itSub != subElements.end(); itSub++) { const std::vector<App::DocumentObject*> &Objs = References3D.getValues();
//int rc = const std::vector<std::string> &Subs = References3D.getSubValues();
static_cast<void> (measurement->addReference3D(obj,(*itSub).c_str())); int end = Objs.size();
} int i = 0;
for ( ; i < end; i++) {
static_cast<void> (measurement->addReference3D(Objs.at(i), Subs.at(i)));
}
} }
//delete all previous measurements //delete all previous measurements

View File

@ -35,6 +35,12 @@ class Measurement;
} }
namespace TechDraw namespace TechDraw
{ {
class DrawViewPart;
struct DimRef {
DrawViewPart* part;
std::string sub;
};
class DrawViewPart; class DrawViewPart;
@ -86,6 +92,8 @@ public:
static int getRefType1(const std::string s); static int getRefType1(const std::string s);
static int getRefType2(const std::string s1, const std::string s2); static int getRefType2(const std::string s1, const std::string s2);
int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge
void setAll3DMeasurement();
void clear3DMeasurements(void);
protected: protected:
void onChanged(const App::Property* prop); void onChanged(const App::Property* prop);
@ -95,8 +103,6 @@ protected:
protected: protected:
Measure::Measurement *measurement; Measure::Measurement *measurement;
void set3DMeasurement(DocumentObject* const &obj, const std::vector<std::string>& subElements);
void clear3DMeasurements(void);
double dist2Segs(Base::Vector2D s1, double dist2Segs(Base::Vector2D s1,
Base::Vector2D e1, Base::Vector2D e1,
Base::Vector2D s2, Base::Vector2D s2,

View File

@ -865,14 +865,20 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
return; return;
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(); std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
Part::Feature* obj3D = 0;
App::DocumentObject* obj3D = 0;
std::vector<App::DocumentObject*> parts;
std::vector<std::string> subs; std::vector<std::string> subs;
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin(); std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
for (; itSel != selection.end(); itSel++) { for (; itSel != selection.end(); itSel++) {
if ((*itSel).getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) { if ((*itSel).getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
obj3D = static_cast<Part::Feature*> ((*itSel).getObject()); obj3D = ((*itSel).getObject());
subs = (*itSel).getSubNames(); std::vector<std::string> subList = (*itSel).getSubNames();
for (auto& s:subList) {
parts.push_back(obj3D);
subs.push_back(s);
}
} }
} }
@ -890,7 +896,7 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
// dialog to select the Dimension to link // dialog to select the Dimension to link
Gui::Control().showDialog(new TaskDlgLinkDim(obj3D,subs,page)); Gui::Control().showDialog(new TaskDlgLinkDim(parts,subs,page));
page->getDocument()->recompute(); //still need to recompute in Gui. why? page->getDocument()->recompute(); //still need to recompute in Gui. why?
} }

View File

@ -54,9 +54,9 @@ using namespace TechDraw;
using namespace TechDrawGui; using namespace TechDrawGui;
TaskLinkDim::TaskLinkDim(Part::Feature* part, std::vector<std::string>& subs, TechDraw::DrawPage* page) : TaskLinkDim::TaskLinkDim(std::vector<App::DocumentObject*> parts, std::vector<std::string>& subs, TechDraw::DrawPage* page) :
ui(new Ui_TaskLinkDim), ui(new Ui_TaskLinkDim),
m_part(part), m_parts(parts),
m_subs(subs), m_subs(subs),
m_page(page) m_page(page)
{ {
@ -71,11 +71,16 @@ TaskLinkDim::TaskLinkDim(Part::Feature* part, std::vector<std::string>& subs, Te
loadAvailDims(); loadAvailDims();
ui->leFeature->setText(QString::fromStdString(part->getNameInDocument())); ui->leFeature1->setText(QString::fromStdString(parts.at(0)->getNameInDocument()));
ui->leGeometry1->setText(QString::fromStdString(subs.at(0))); ui->leGeometry1->setText(QString::fromStdString(subs.at(0)));
if (subs.size() > 1) { if (subs.size() > 1) {
ui->leGeometry2->setText(QString::fromStdString(subs.at(1))); ui->leGeometry2->setText(QString::fromStdString(subs.at(1)));
if (parts.at(0)->getNameInDocument() != parts.at(1)->getNameInDocument()) {
ui->leFeature2->setText(QString::fromStdString(parts.at(1)->getNameInDocument()));
} else {
ui->leFeature2->clear();
}
} }
} }
@ -149,26 +154,37 @@ bool TaskLinkDim::dimReferencesSelection(const TechDraw::DrawViewDimension* dim)
return result; return result;
} }
Part::Feature* refPart = static_cast<Part::Feature*>(dim->References3D.getValues().at(0)); //Part::Feature* refPart = static_cast<Part::Feature*>(dim->References3D.getValues().at(0));
std::vector<Part::Feature*> refParts;
std::vector<App::DocumentObject*> docObjs = dim->References3D.getValues();
for (auto& d: docObjs) {
Part::Feature* part = static_cast<Part::Feature*>(d);
refParts.push_back(part);
}
std::vector<std::string> refSubs = dim->References3D.getSubValues(); std::vector<std::string> refSubs = dim->References3D.getSubValues();
if (refPart == m_part) { if (refParts.size() == m_parts.size()) {
if (refSubs.size() == m_subs.size()) { if(refParts.size() == 0) {
if (m_subs.size() == 0) { //shouldn't happen!
//we're done. why did we get here? } else if (refParts.size() == 1) {
} else if (refSubs.size() == 1) { if ((refParts[0] == m_parts[0]) &&
if (refSubs[0] == m_subs[0]) { (refSubs[0] == m_subs[0]) ) { //everything matches
result = true; result = true;
} }
} else { } else if (refParts.size() == 2) {
if ( ((refSubs[0] == m_subs[0]) && if (( (refParts[0] == m_parts[0]) &&
(refSubs[1] == m_subs[1])) || (refParts[1] == m_parts[1]) ) &&
((refSubs[0] == m_subs[1]) && ( (refSubs[0] == m_subs[0]) &&
(refSubs[1] == m_subs[0])) ) { (refSubs[1] == m_subs[1]) ) ) {
result = true; result = true;
} } else if (( (refParts[0] == m_parts[1]) &&
(refParts[1] == m_parts[0]) ) &&
( (refSubs[0] == m_subs[1]) &&
(refSubs[1] == m_subs[0]) ) ) {
result = true;
} }
} }
} }
return result; return result;
} }
@ -182,11 +198,11 @@ void TaskLinkDim::updateDims()
QString name = child->data(0, Qt::UserRole).toString(); QString name = child->data(0, Qt::UserRole).toString();
App::DocumentObject* obj = m_page->getDocument()->getObject(name.toStdString().c_str()); App::DocumentObject* obj = m_page->getDocument()->getObject(name.toStdString().c_str());
TechDraw::DrawViewDimension* dim = dynamic_cast<TechDraw::DrawViewDimension*>(obj); TechDraw::DrawViewDimension* dim = dynamic_cast<TechDraw::DrawViewDimension*>(obj);
std::vector<App::DocumentObject*> parts; // std::vector<App::DocumentObject*> parts;
for (unsigned int iPart = 0; iPart < m_subs.size(); iPart++) { // for (unsigned int iPart = 0; iPart < m_subs.size(); iPart++) {
parts.push_back(m_part); // parts.push_back(m_part);
} // }
dim->References3D.setValues(parts,m_subs); dim->References3D.setValues(m_parts,m_subs);
std::string DimName = dim->getNameInDocument(); std::string DimName = dim->getNameInDocument();
std::string measureType = "True"; std::string measureType = "True";
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'", Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'",
@ -204,8 +220,8 @@ void TaskLinkDim::updateDims()
std::string DimName = dim->getNameInDocument(); std::string DimName = dim->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'", Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'",
DimName.c_str(),measureType.c_str()); DimName.c_str(),measureType.c_str());
dim->References3D.setValue(0,""); //set this property to "empty" dim->References3D.setValue(0,""); //DVD.References3D
//dim->MeasureType.setValue("Projected"); dim->clear3DMeasurements(); //DVD.measurement.References3D
} }
} }
} }
@ -256,10 +272,10 @@ void TaskLinkDim::changeEvent(QEvent *e)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TaskDlgLinkDim::TaskDlgLinkDim(Part::Feature* part,std::vector<std::string>& subs, TechDraw::DrawPage* page) : TaskDlgLinkDim::TaskDlgLinkDim(std::vector<App::DocumentObject*> parts,std::vector<std::string>& subs, TechDraw::DrawPage* page) :
TaskDialog() TaskDialog()
{ {
widget = new TaskLinkDim(part,subs,page); widget = new TaskLinkDim(parts,subs,page);
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Dimension_Link"), taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Dimension_Link"),
widget->windowTitle(), true, 0); widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget); taskbox->groupLayout()->addWidget(widget);

View File

@ -45,7 +45,7 @@ class TaskLinkDim : public QWidget
Q_OBJECT Q_OBJECT
public: public:
TaskLinkDim(Part::Feature* part,std::vector<std::string>& subs, TechDraw::DrawPage* page); TaskLinkDim(std::vector<App::DocumentObject*> parts,std::vector<std::string>& subs, TechDraw::DrawPage* page);
~TaskLinkDim(); ~TaskLinkDim();
public: public:
@ -64,8 +64,8 @@ protected:
private: private:
Ui_TaskLinkDim * ui; Ui_TaskLinkDim * ui;
Part::Feature* m_part; const std::vector<App::DocumentObject*> m_parts;
std::vector<std::string> m_subs; const std::vector<std::string> m_subs;
TechDraw::DrawPage* m_page; TechDraw::DrawPage* m_page;
}; };
@ -74,7 +74,7 @@ class TaskDlgLinkDim : public Gui::TaskView::TaskDialog
Q_OBJECT Q_OBJECT
public: public:
TaskDlgLinkDim(Part::Feature* part,std::vector<std::string>& subs, TechDraw::DrawPage* page); TaskDlgLinkDim(std::vector<App::DocumentObject*> parts,std::vector<std::string>& subs, TechDraw::DrawPage* page);
~TaskDlgLinkDim(); ~TaskDlgLinkDim();
public: public:

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>342</width> <width>400</width>
<height>430</height> <height>472</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -61,7 +61,7 @@
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="2" column="1"> <item row="3" column="1">
<widget class="QLineEdit" name="leGeometry2"> <widget class="QLineEdit" name="leGeometry2">
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::NoFocus</enum> <enum>Qt::NoFocus</enum>
@ -74,10 +74,43 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="2" column="0">
<widget class="QLabel" name="lblGeometry"> <widget class="QLabel" name="lblGeometry">
<property name="text"> <property name="text">
<string>Geometry:</string> <string>Feature2:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="leFeature2">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(120, 120, 120);</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leFeature1">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(120, 120, 120);</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblFeature">
<property name="text">
<string>Feature1:</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -94,23 +127,17 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="0">
<widget class="QLineEdit" name="leFeature"> <widget class="QLabel" name="label">
<property name="focusPolicy"> <property name="text">
<enum>Qt::NoFocus</enum> <string>Geometry1:</string>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(120, 120, 120);</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="3" column="0">
<widget class="QLabel" name="lblFeature"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Feature:</string> <string>Geometry2: </string>
</property> </property>
</widget> </widget>
</item> </item>