[PD] shape binder: code style improvements
all done by MSVC
This commit is contained in:
@@ -67,10 +67,10 @@ ViewProviderShapeBinder::ViewProviderShapeBinder()
|
||||
|
||||
//get the datum coloring scheme
|
||||
// set default color for datums (golden yellow with 60% transparency)
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath (
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign");
|
||||
unsigned long shcol = hGrp->GetUnsigned ( "DefaultDatumColor", 0xFFD70099 );
|
||||
App::Color col ( (uint32_t) shcol );
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign");
|
||||
unsigned long shcol = hGrp->GetUnsigned("DefaultDatumColor", 0xFFD70099);
|
||||
App::Color col((uint32_t)shcol);
|
||||
|
||||
ShapeColor.setValue(col);
|
||||
LineColor.setValue(col);
|
||||
@@ -91,8 +91,8 @@ bool ViewProviderShapeBinder::setEdit(int ModNum) {
|
||||
// When double-clicking on the item for this pad the
|
||||
// object unsets and sets its edit mode without closing
|
||||
// the task panel
|
||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
||||
TaskDlgShapeBinder *sbDlg = qobject_cast<TaskDlgShapeBinder*>(dlg);
|
||||
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
|
||||
TaskDlgShapeBinder* sbDlg = qobject_cast<TaskDlgShapeBinder*>(dlg);
|
||||
if (dlg && !sbDlg) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
|
||||
@@ -114,7 +114,7 @@ bool ViewProviderShapeBinder::setEdit(int ModNum) {
|
||||
if (sbDlg)
|
||||
Gui::Control().showDialog(sbDlg);
|
||||
else
|
||||
Gui::Control().showDialog(new TaskDlgShapeBinder(this,ModNum == 1));
|
||||
Gui::Control().showDialog(new TaskDlgShapeBinder(this, ModNum == 1));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -143,11 +143,11 @@ void ViewProviderShapeBinder::highlightReferences(const bool on, bool /*auxiliar
|
||||
return;
|
||||
|
||||
PartGui::ViewProviderPart* svp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(obj));
|
||||
Gui::Application::Instance->getViewProvider(obj));
|
||||
if (svp == nullptr) return;
|
||||
|
||||
if (on) {
|
||||
if (!subs.empty() && originalLineColors.empty()) {
|
||||
if (!subs.empty() && originalLineColors.empty()) {
|
||||
TopTools_IndexedMapOfShape eMap;
|
||||
TopExp::MapShapes(static_cast<Part::Feature*>(obj)->Shape.getValue(), TopAbs_EDGE, eMap);
|
||||
originalLineColors = svp->LineColorArray.getValues();
|
||||
@@ -161,23 +161,24 @@ void ViewProviderShapeBinder::highlightReferences(const bool on, bool /*auxiliar
|
||||
|
||||
for (std::string e : subs) {
|
||||
// Note: stoi may throw, but it strictly shouldn't happen
|
||||
if(e.compare(0, 4, "Edge") == 0) {
|
||||
if (e.compare(0, 4, "Edge") == 0) {
|
||||
int idx = std::stoi(e.substr(4)) - 1;
|
||||
assert ( idx>=0 );
|
||||
if ( idx < (ssize_t) lcolors.size() )
|
||||
lcolors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
assert(idx >= 0);
|
||||
if (idx < (ssize_t)lcolors.size())
|
||||
lcolors[idx] = App::Color(1.0, 0.0, 1.0); // magenta
|
||||
}
|
||||
else if(e.compare(0, 4, "Face") == 0) {
|
||||
else if (e.compare(0, 4, "Face") == 0) {
|
||||
int idx = std::stoi(e.substr(4)) - 1;
|
||||
assert ( idx>=0 );
|
||||
if ( idx < (ssize_t) fcolors.size() )
|
||||
fcolors[idx] = App::Color(1.0,0.0,1.0); // magenta
|
||||
assert(idx >= 0);
|
||||
if (idx < (ssize_t)fcolors.size())
|
||||
fcolors[idx] = App::Color(1.0, 0.0, 1.0); // magenta
|
||||
}
|
||||
}
|
||||
svp->LineColorArray.setValues(lcolors);
|
||||
svp->DiffuseColor.setValues(fcolors);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (!subs.empty() && !originalLineColors.empty()) {
|
||||
svp->LineColorArray.setValues(originalLineColors);
|
||||
originalLineColors.clear();
|
||||
@@ -193,7 +194,7 @@ void ViewProviderShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver, c
|
||||
Q_UNUSED(receiver)
|
||||
Q_UNUSED(member)
|
||||
|
||||
QAction* act;
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr("Edit shape binder"));
|
||||
act->setData(QVariant((int)ViewProvider::Default));
|
||||
|
||||
@@ -211,37 +212,38 @@ void ViewProviderShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver, c
|
||||
|
||||
//=====================================================================================
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderSubShapeBinder,PartGui::ViewProviderPart)
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderSubShapeBinder, PartGui::ViewProviderPart)
|
||||
|
||||
ViewProviderSubShapeBinder::ViewProviderSubShapeBinder() {
|
||||
sPixmap = "PartDesign_SubShapeBinder.svg";
|
||||
|
||||
ADD_PROPERTY_TYPE(UseBinderStyle, (false), "",(App::PropertyType)(App::Prop_None), "");
|
||||
ADD_PROPERTY_TYPE(UseBinderStyle, (false), "", (App::PropertyType)(App::Prop_None), "");
|
||||
}
|
||||
|
||||
void ViewProviderSubShapeBinder::attach(App::DocumentObject *obj) {
|
||||
void ViewProviderSubShapeBinder::attach(App::DocumentObject* obj) {
|
||||
|
||||
UseBinderStyle.setValue(boost::istarts_with(obj->getNameInDocument(),"binder"));
|
||||
UseBinderStyle.setValue(boost::istarts_with(obj->getNameInDocument(), "binder"));
|
||||
ViewProviderPart::attach(obj);
|
||||
}
|
||||
|
||||
void ViewProviderSubShapeBinder::onChanged(const App::Property *prop) {
|
||||
if(prop == &UseBinderStyle
|
||||
&& (!getObject() || !getObject()->isRestoring()))
|
||||
void ViewProviderSubShapeBinder::onChanged(const App::Property* prop) {
|
||||
if (prop == &UseBinderStyle
|
||||
&& (!getObject() || !getObject()->isRestoring()))
|
||||
{
|
||||
App::Color shapeColor,lineColor,pointColor;
|
||||
App::Color shapeColor, lineColor, pointColor;
|
||||
int transparency, linewidth;
|
||||
if(UseBinderStyle.getValue()) {
|
||||
if (UseBinderStyle.getValue()) {
|
||||
//get the datum coloring scheme
|
||||
// set default color for datums (golden yellow with 60% transparency)
|
||||
static ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath (
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign");
|
||||
shapeColor.setPackedValue(hGrp->GetUnsigned ( "DefaultDatumColor", 0xFFD70099 ));
|
||||
static ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign");
|
||||
shapeColor.setPackedValue(hGrp->GetUnsigned("DefaultDatumColor", 0xFFD70099));
|
||||
lineColor = shapeColor;
|
||||
pointColor = shapeColor;
|
||||
transparency = 60;
|
||||
linewidth = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
shapeColor.setPackedValue(Gui::ViewParams::instance()->getDefaultShapeColor());
|
||||
lineColor.setPackedValue(Gui::ViewParams::instance()->getDefaultShapeLineColor());
|
||||
pointColor = lineColor;
|
||||
@@ -258,35 +260,36 @@ void ViewProviderSubShapeBinder::onChanged(const App::Property *prop) {
|
||||
ViewProviderPart::onChanged(prop);
|
||||
}
|
||||
|
||||
bool ViewProviderSubShapeBinder::canDropObjectEx(App::DocumentObject *,
|
||||
App::DocumentObject *, const char *, const std::vector<std::string> &) const
|
||||
bool ViewProviderSubShapeBinder::canDropObjectEx(App::DocumentObject*,
|
||||
App::DocumentObject*, const char*, const std::vector<std::string>&) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string ViewProviderSubShapeBinder::dropObjectEx(App::DocumentObject *obj, App::DocumentObject *owner,
|
||||
const char *subname, const std::vector<std::string> &elements)
|
||||
std::string ViewProviderSubShapeBinder::dropObjectEx(App::DocumentObject* obj, App::DocumentObject* owner,
|
||||
const char* subname, const std::vector<std::string>& elements)
|
||||
{
|
||||
auto self = dynamic_cast<PartDesign::SubShapeBinder*>(getObject());
|
||||
if(!self) return std::string();
|
||||
std::map<App::DocumentObject *, std::vector<std::string> > values;
|
||||
if(!subname) subname = "";
|
||||
if (!self) return std::string();
|
||||
std::map<App::DocumentObject*, std::vector<std::string> > values;
|
||||
if (!subname) subname = "";
|
||||
std::string sub(subname);
|
||||
if(sub.empty())
|
||||
values[owner?owner:obj] = elements;
|
||||
if (sub.empty())
|
||||
values[owner ? owner : obj] = elements;
|
||||
else {
|
||||
std::vector<std::string> subs;
|
||||
if(elements.size()) {
|
||||
if (elements.size()) {
|
||||
subs.reserve(elements.size());
|
||||
for(auto &element : elements)
|
||||
subs.push_back(sub+element);
|
||||
}else
|
||||
for (auto& element : elements)
|
||||
subs.push_back(sub + element);
|
||||
}
|
||||
else
|
||||
subs.push_back(sub);
|
||||
values[owner?owner:obj] = std::move(subs);
|
||||
values[owner ? owner : obj] = std::move(subs);
|
||||
}
|
||||
|
||||
self->setLinks(std::move(values),QApplication::keyboardModifiers()==Qt::ControlModifier);
|
||||
if(self->Relative.getValue())
|
||||
self->setLinks(std::move(values), QApplication::keyboardModifiers() == Qt::ControlModifier);
|
||||
if (self->Relative.getValue())
|
||||
updatePlacement(false);
|
||||
return std::string();
|
||||
}
|
||||
@@ -297,40 +300,40 @@ bool ViewProviderSubShapeBinder::doubleClicked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderSubShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
void ViewProviderSubShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
QAction* act;
|
||||
act = menu->addAction(QObject::tr("Synchronize"), receiver, member);
|
||||
act->setData(QVariant((int)Synchronize));
|
||||
act = menu->addAction(QObject::tr("Select bound object"), receiver, member);
|
||||
act->setData(QVariant((int)SelectObject));
|
||||
ViewProviderPart::setupContextMenu(menu,receiver,member);
|
||||
ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderSubShapeBinder::setEdit(int ModNum) {
|
||||
|
||||
switch(ModNum) {
|
||||
|
||||
switch (ModNum) {
|
||||
case Synchronize:
|
||||
updatePlacement(true);
|
||||
break;
|
||||
case SelectObject: {
|
||||
auto self = dynamic_cast<PartDesign::SubShapeBinder*>(getObject());
|
||||
if(!self || !self->Support.getValue())
|
||||
if (!self || !self->Support.getValue())
|
||||
break;
|
||||
|
||||
Gui::Selection().selStackPush();
|
||||
Gui::Selection().clearSelection();
|
||||
for(auto &link : self->Support.getSubListValues()) {
|
||||
for (auto& link : self->Support.getSubListValues()) {
|
||||
auto obj = link.getValue();
|
||||
if(!obj || !obj->getNameInDocument())
|
||||
if (!obj || !obj->getNameInDocument())
|
||||
continue;
|
||||
const auto &subs = link.getSubValues();
|
||||
if(subs.size())
|
||||
const auto& subs = link.getSubValues();
|
||||
if (subs.size())
|
||||
Gui::Selection().addSelections(obj->getDocument()->getName(),
|
||||
obj->getNameInDocument(),subs);
|
||||
obj->getNameInDocument(), subs);
|
||||
else
|
||||
Gui::Selection().addSelection(obj->getDocument()->getName(),
|
||||
obj->getNameInDocument());
|
||||
obj->getNameInDocument());
|
||||
}
|
||||
Gui::Selection().selStackPush();
|
||||
break;
|
||||
@@ -343,74 +346,78 @@ bool ViewProviderSubShapeBinder::setEdit(int ModNum) {
|
||||
|
||||
void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {
|
||||
auto self = dynamic_cast<PartDesign::SubShapeBinder*>(getObject());
|
||||
if(!self || !self->Support.getValue())
|
||||
if (!self || !self->Support.getValue())
|
||||
return;
|
||||
|
||||
std::vector<Base::Matrix4D> mats;
|
||||
bool relative = self->Relative.getValue();
|
||||
App::DocumentObject *parent = nullptr;
|
||||
App::DocumentObject* parent = nullptr;
|
||||
std::string parentSub;
|
||||
if(relative && self->getParents().size()) {
|
||||
const auto &sel = Gui::Selection().getSelection("",0);
|
||||
if(sel.size()!=1 || !sel[0].pObject ||
|
||||
sel[0].pObject->getSubObject(sel[0].SubName)!=self)
|
||||
if (relative && self->getParents().size()) {
|
||||
const auto& sel = Gui::Selection().getSelection("", 0);
|
||||
if (sel.size() != 1 || !sel[0].pObject ||
|
||||
sel[0].pObject->getSubObject(sel[0].SubName) != self)
|
||||
{
|
||||
FC_WARN("invalid selection");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
parent = sel[0].pObject;
|
||||
parentSub = sel[0].SubName;
|
||||
}
|
||||
}
|
||||
|
||||
if(!transaction) {
|
||||
if(relative)
|
||||
self->Context.setValue(parent,parentSub.c_str());
|
||||
if (!transaction) {
|
||||
if (relative)
|
||||
self->Context.setValue(parent, parentSub.c_str());
|
||||
try {
|
||||
self->update(PartDesign::SubShapeBinder::UpdateForced);
|
||||
} catch (Base::Exception &e) {
|
||||
}
|
||||
catch (Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
App::GetApplication().setActiveTransaction("Sync binder");
|
||||
try{
|
||||
if(relative)
|
||||
self->Context.setValue(parent,parentSub.c_str());
|
||||
try {
|
||||
if (relative)
|
||||
self->Context.setValue(parent, parentSub.c_str());
|
||||
self->update(PartDesign::SubShapeBinder::UpdateForced);
|
||||
App::GetApplication().closeActiveTransaction();
|
||||
return;
|
||||
}catch(Base::Exception &e) {
|
||||
}
|
||||
catch (Base::Exception& e) {
|
||||
e.ReportException();
|
||||
}catch(Standard_Failure &e) {
|
||||
}
|
||||
catch (Standard_Failure& e) {
|
||||
std::ostringstream str;
|
||||
Standard_CString msg = e.GetMessageString();
|
||||
str << typeid(e).name() << " ";
|
||||
if (msg) {str << msg;}
|
||||
else {str << "No OCCT Exception Message";}
|
||||
if (msg) { str << msg; }
|
||||
else { str << "No OCCT Exception Message"; }
|
||||
FC_ERR(str.str());
|
||||
}
|
||||
App::GetApplication().closeActiveTransaction(true);
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderSubShapeBinder::claimChildren(void) const {
|
||||
std::vector<App::DocumentObject *> ret;
|
||||
std::vector<App::DocumentObject*> ret;
|
||||
auto self = Base::freecad_dynamic_cast<PartDesign::SubShapeBinder>(getObject());
|
||||
if(self && self->ClaimChildren.getValue() && self->Support.getValue()) {
|
||||
std::set<App::DocumentObject *> objSet;
|
||||
for(auto &l : self->Support.getSubListValues()) {
|
||||
if (self && self->ClaimChildren.getValue() && self->Support.getValue()) {
|
||||
std::set<App::DocumentObject*> objSet;
|
||||
for (auto& l : self->Support.getSubListValues()) {
|
||||
auto obj = l.getValue();
|
||||
if(!obj)
|
||||
if (!obj)
|
||||
continue;
|
||||
const auto &subs = l.getSubValues();
|
||||
if(subs.empty()) {
|
||||
if(objSet.insert(obj).second)
|
||||
const auto& subs = l.getSubValues();
|
||||
if (subs.empty()) {
|
||||
if (objSet.insert(obj).second)
|
||||
ret.push_back(obj);
|
||||
continue;
|
||||
}
|
||||
for(auto &sub : subs) {
|
||||
for (auto& sub : subs) {
|
||||
auto sobj = obj->getSubObject(sub.c_str());
|
||||
if(sobj && objSet.insert(sobj).second)
|
||||
if (sobj && objSet.insert(sobj).second)
|
||||
ret.push_back(sobj);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user