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);
}
//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
int Measurement::addReference3D(App::DocumentObject *obj, const char* subName)
{

View File

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

View File

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

View File

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

View File

@ -865,14 +865,20 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
return;
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<Gui::SelectionObject>::iterator itSel = selection.begin();
for (; itSel != selection.end(); itSel++) {
if ((*itSel).getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
obj3D = static_cast<Part::Feature*> ((*itSel).getObject());
subs = (*itSel).getSubNames();
obj3D = ((*itSel).getObject());
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
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?
}

View File

@ -54,9 +54,9 @@ using namespace TechDraw;
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),
m_part(part),
m_parts(parts),
m_subs(subs),
m_page(page)
{
@ -71,11 +71,16 @@ TaskLinkDim::TaskLinkDim(Part::Feature* part, std::vector<std::string>& subs, Te
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)));
if (subs.size() > 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;
}
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();
if (refPart == m_part) {
if (refSubs.size() == m_subs.size()) {
if (m_subs.size() == 0) {
//we're done. why did we get here?
} else if (refSubs.size() == 1) {
if (refSubs[0] == m_subs[0]) {
result = true;
}
} else {
if ( ((refSubs[0] == m_subs[0]) &&
(refSubs[1] == m_subs[1])) ||
((refSubs[0] == m_subs[1]) &&
(refSubs[1] == m_subs[0])) ) {
result = true;
}
if (refParts.size() == m_parts.size()) {
if(refParts.size() == 0) {
//shouldn't happen!
} else if (refParts.size() == 1) {
if ((refParts[0] == m_parts[0]) &&
(refSubs[0] == m_subs[0]) ) { //everything matches
result = true;
}
} else if (refParts.size() == 2) {
if (( (refParts[0] == m_parts[0]) &&
(refParts[1] == m_parts[1]) ) &&
( (refSubs[0] == m_subs[0]) &&
(refSubs[1] == m_subs[1]) ) ) {
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;
}
@ -182,11 +198,11 @@ void TaskLinkDim::updateDims()
QString name = child->data(0, Qt::UserRole).toString();
App::DocumentObject* obj = m_page->getDocument()->getObject(name.toStdString().c_str());
TechDraw::DrawViewDimension* dim = dynamic_cast<TechDraw::DrawViewDimension*>(obj);
std::vector<App::DocumentObject*> parts;
for (unsigned int iPart = 0; iPart < m_subs.size(); iPart++) {
parts.push_back(m_part);
}
dim->References3D.setValues(parts,m_subs);
// std::vector<App::DocumentObject*> parts;
// for (unsigned int iPart = 0; iPart < m_subs.size(); iPart++) {
// parts.push_back(m_part);
// }
dim->References3D.setValues(m_parts,m_subs);
std::string DimName = dim->getNameInDocument();
std::string measureType = "True";
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'",
@ -204,8 +220,8 @@ void TaskLinkDim::updateDims()
std::string DimName = dim->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().%s.MeasureType = \'%s\'",
DimName.c_str(),measureType.c_str());
dim->References3D.setValue(0,""); //set this property to "empty"
//dim->MeasureType.setValue("Projected");
dim->References3D.setValue(0,""); //DVD.References3D
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()
{
widget = new TaskLinkDim(part,subs,page);
widget = new TaskLinkDim(parts,subs,page);
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_Dimension_Link"),
widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget);

View File

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

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>342</width>
<height>430</height>
<width>400</width>
<height>472</height>
</rect>
</property>
<property name="sizePolicy">
@ -61,7 +61,7 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="leGeometry2">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
@ -74,10 +74,43 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="lblGeometry">
<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>
</widget>
</item>
@ -94,23 +127,17 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leFeature">
<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>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Geometry1:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblFeature">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Feature:</string>
<string>Geometry2: </string>
</property>
</widget>
</item>