All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
eafd18dac0
commit
25c3ba7338
@@ -21,12 +21,11 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
# include <QApplication>
|
||||
# include <QMenu>
|
||||
# include <QMessageBox>
|
||||
# include <TopExp.hxx>
|
||||
# include <TopTools_IndexedMapOfShape.hxx>
|
||||
#include <QApplication>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <TopExp.hxx>
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
@@ -43,17 +42,17 @@
|
||||
#include "ViewProviderShapeBinder.h"
|
||||
#include "TaskShapeBinder.h"
|
||||
|
||||
FC_LOG_LEVEL_INIT("ShapeBinder",true,true)
|
||||
FC_LOG_LEVEL_INIT("ShapeBinder", true, true)
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderShapeBinder,PartGui::ViewProviderPart)
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderShapeBinder, PartGui::ViewProviderPart)
|
||||
|
||||
ViewProviderShapeBinder::ViewProviderShapeBinder()
|
||||
{
|
||||
sPixmap = "PartDesign_ShapeBinder.svg";
|
||||
|
||||
//make the viewprovider more datum like
|
||||
// make the viewprovider more datum like
|
||||
AngularDeflection.setStatus(App::Property::Hidden, true);
|
||||
Deviation.setStatus(App::Property::Hidden, true);
|
||||
DrawStyle.setStatus(App::Property::Hidden, true);
|
||||
@@ -64,10 +63,11 @@ ViewProviderShapeBinder::ViewProviderShapeBinder()
|
||||
PointSize.setStatus(App::Property::Hidden, true);
|
||||
DisplayMode.setStatus(App::Property::Hidden, true);
|
||||
|
||||
//get the datum coloring scheme
|
||||
// set default color for datums (golden yellow with 60% transparency)
|
||||
// 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");
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign"
|
||||
);
|
||||
unsigned long shcol = hGrp->GetUnsigned("DefaultDatumColor", 0xFFD70099);
|
||||
Base::Color col((uint32_t)shcol);
|
||||
|
||||
@@ -80,7 +80,8 @@ ViewProviderShapeBinder::ViewProviderShapeBinder()
|
||||
|
||||
ViewProviderShapeBinder::~ViewProviderShapeBinder() = default;
|
||||
|
||||
bool ViewProviderShapeBinder::setEdit(int ModNum) {
|
||||
bool ViewProviderShapeBinder::setEdit(int ModNum)
|
||||
{
|
||||
// TODO Share code with other view providers (2015-09-11, Fat-Zer)
|
||||
|
||||
if (ModNum == ViewProvider::Default || ModNum == 1) {
|
||||
@@ -96,10 +97,12 @@ bool ViewProviderShapeBinder::setEdit(int ModNum) {
|
||||
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
msgBox.setDefaultButton(QMessageBox::Yes);
|
||||
int ret = msgBox.exec();
|
||||
if (ret == QMessageBox::Yes)
|
||||
if (ret == QMessageBox::Yes) {
|
||||
Gui::Control().reject();
|
||||
else
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// clear the selection (convenience)
|
||||
@@ -107,10 +110,12 @@ bool ViewProviderShapeBinder::setEdit(int ModNum) {
|
||||
|
||||
// start the edit dialog
|
||||
// another pad left open its task panel
|
||||
if (sbDlg)
|
||||
if (sbDlg) {
|
||||
Gui::Control().showDialog(sbDlg);
|
||||
else
|
||||
}
|
||||
else {
|
||||
Gui::Control().showDialog(new TaskDlgShapeBinder(this, ModNum == 1));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -119,12 +124,13 @@ bool ViewProviderShapeBinder::setEdit(int ModNum) {
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderShapeBinder::unsetEdit(int ModNum) {
|
||||
void ViewProviderShapeBinder::unsetEdit(int ModNum)
|
||||
{
|
||||
|
||||
PartGui::ViewProviderPart::unsetEdit(ModNum);
|
||||
}
|
||||
|
||||
void ViewProviderShapeBinder::attach(App::DocumentObject *obj)
|
||||
void ViewProviderShapeBinder::attach(App::DocumentObject* obj)
|
||||
{
|
||||
if (auto geo = dynamic_cast<App::GeoFeature*>(obj)) {
|
||||
geo->setMaterialAppearance(ShapeAppearance[0]);
|
||||
@@ -137,19 +143,28 @@ void ViewProviderShapeBinder::highlightReferences(bool on)
|
||||
App::GeoFeature* obj = nullptr;
|
||||
std::vector<std::string> subs;
|
||||
|
||||
if (getObject()->isDerivedFrom<PartDesign::ShapeBinder>())
|
||||
PartDesign::ShapeBinder::getFilteredReferences(&getObject<PartDesign::ShapeBinder>()->Support, obj, subs);
|
||||
else
|
||||
if (getObject()->isDerivedFrom<PartDesign::ShapeBinder>()) {
|
||||
PartDesign::ShapeBinder::getFilteredReferences(
|
||||
&getObject<PartDesign::ShapeBinder>()->Support,
|
||||
obj,
|
||||
subs
|
||||
);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
// stop if not a Part feature was found
|
||||
if (!obj || !obj->isDerivedFrom<Part::Feature>())
|
||||
if (!obj || !obj->isDerivedFrom<Part::Feature>()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PartGui::ViewProviderPart* svp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(obj));
|
||||
if (!svp)
|
||||
Gui::Application::Instance->getViewProvider(obj)
|
||||
);
|
||||
if (!svp) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (on) {
|
||||
if (!subs.empty() && originalLineColors.empty()) {
|
||||
@@ -169,14 +184,16 @@ void ViewProviderShapeBinder::highlightReferences(bool on)
|
||||
if (e.compare(0, 4, "Edge") == 0) {
|
||||
int idx = std::stoi(e.substr(4)) - 1;
|
||||
assert(idx >= 0);
|
||||
if (idx < static_cast<int>(lcolors.size()))
|
||||
lcolors[idx] = Base::Color(1.0, 0.0, 1.0); // magenta
|
||||
if (idx < static_cast<int>(lcolors.size())) {
|
||||
lcolors[idx] = Base::Color(1.0, 0.0, 1.0); // magenta
|
||||
}
|
||||
}
|
||||
else if (e.compare(0, 4, "Face") == 0) {
|
||||
int idx = std::stoi(e.substr(4)) - 1;
|
||||
assert(idx >= 0);
|
||||
if (idx < static_cast<int>(fcolors.size()))
|
||||
fcolors[idx].diffuseColor = Base::Color(1.0, 0.0, 1.0); // magenta
|
||||
if (idx < static_cast<int>(fcolors.size())) {
|
||||
fcolors[idx].diffuseColor = Base::Color(1.0, 0.0, 1.0); // magenta
|
||||
}
|
||||
}
|
||||
}
|
||||
svp->LineColorArray.setValues(lcolors);
|
||||
@@ -199,7 +216,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));
|
||||
|
||||
@@ -219,13 +236,15 @@ void ViewProviderShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver, c
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderSubShapeBinder, PartGui::ViewProviderPart)
|
||||
|
||||
ViewProviderSubShapeBinder::ViewProviderSubShapeBinder() {
|
||||
ViewProviderSubShapeBinder::ViewProviderSubShapeBinder()
|
||||
{
|
||||
sPixmap = "PartDesign_SubShapeBinder.svg";
|
||||
|
||||
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"));
|
||||
if (auto geo = dynamic_cast<App::GeoFeature*>(obj)) {
|
||||
@@ -234,17 +253,17 @@ void ViewProviderSubShapeBinder::attach(App::DocumentObject* obj) {
|
||||
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())) {
|
||||
Base::Color shapeColor, lineColor, pointColor;
|
||||
int transparency, linewidth;
|
||||
if (UseBinderStyle.getValue()) {
|
||||
//get the datum coloring scheme
|
||||
// set default color for datums (golden yellow with 60% transparency)
|
||||
// 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");
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign"
|
||||
);
|
||||
shapeColor.setPackedValue(hGrp->GetUnsigned("DefaultDatumColor", 0xFFD70099));
|
||||
lineColor = shapeColor;
|
||||
pointColor = shapeColor;
|
||||
@@ -268,43 +287,59 @@ 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 = getObject<PartDesign::SubShapeBinder>();
|
||||
if (!self)
|
||||
if (!self) {
|
||||
return {};
|
||||
std::map<App::DocumentObject*, std::vector<std::string> > values;
|
||||
if (!subname) subname = "";
|
||||
}
|
||||
std::map<App::DocumentObject*, std::vector<std::string>> values;
|
||||
if (!subname) {
|
||||
subname = "";
|
||||
}
|
||||
std::string sub(subname);
|
||||
if (sub.empty())
|
||||
if (sub.empty()) {
|
||||
values[owner ? owner : obj] = elements;
|
||||
}
|
||||
else {
|
||||
std::vector<std::string> subs;
|
||||
if (!elements.empty()) {
|
||||
subs.reserve(elements.size());
|
||||
for (auto& element : elements)
|
||||
for (auto& element : elements) {
|
||||
subs.push_back(sub + element);
|
||||
}
|
||||
}
|
||||
else
|
||||
else {
|
||||
subs.push_back(sub);
|
||||
}
|
||||
values[owner ? owner : obj] = std::move(subs);
|
||||
}
|
||||
|
||||
self->setLinks(std::move(values), QApplication::keyboardModifiers() == Qt::ControlModifier);
|
||||
if (self->Relative.getValue())
|
||||
if (self->Relative.getValue()) {
|
||||
updatePlacement(false);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
bool ViewProviderSubShapeBinder::doubleClicked() {
|
||||
bool ViewProviderSubShapeBinder::doubleClicked()
|
||||
{
|
||||
updatePlacement(true);
|
||||
return true;
|
||||
}
|
||||
@@ -319,44 +354,56 @@ void ViewProviderSubShapeBinder::setupContextMenu(QMenu* menu, QObject* receiver
|
||||
ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderSubShapeBinder::setEdit(int ModNum) {
|
||||
bool ViewProviderSubShapeBinder::setEdit(int ModNum)
|
||||
{
|
||||
|
||||
switch (ModNum) {
|
||||
case Synchronize:
|
||||
updatePlacement(true);
|
||||
break;
|
||||
case SelectObject: {
|
||||
auto self = getObject<PartDesign::SubShapeBinder>();
|
||||
if (!self || !self->Support.getValue())
|
||||
case Synchronize:
|
||||
updatePlacement(true);
|
||||
break;
|
||||
case SelectObject: {
|
||||
auto self = getObject<PartDesign::SubShapeBinder>();
|
||||
if (!self || !self->Support.getValue()) {
|
||||
break;
|
||||
}
|
||||
|
||||
Gui::Selection().selStackPush();
|
||||
Gui::Selection().clearSelection();
|
||||
for (auto& link : self->Support.getSubListValues()) {
|
||||
auto obj = link.getValue();
|
||||
if (!obj || !obj->isAttachedToDocument())
|
||||
continue;
|
||||
const auto& subs = link.getSubValues();
|
||||
if (!subs.empty())
|
||||
Gui::Selection().addSelections(obj->getDocument()->getName(),
|
||||
obj->getNameInDocument(), subs);
|
||||
else
|
||||
Gui::Selection().addSelection(obj->getDocument()->getName(),
|
||||
obj->getNameInDocument());
|
||||
Gui::Selection().selStackPush();
|
||||
Gui::Selection().clearSelection();
|
||||
for (auto& link : self->Support.getSubListValues()) {
|
||||
auto obj = link.getValue();
|
||||
if (!obj || !obj->isAttachedToDocument()) {
|
||||
continue;
|
||||
}
|
||||
const auto& subs = link.getSubValues();
|
||||
if (!subs.empty()) {
|
||||
Gui::Selection().addSelections(
|
||||
obj->getDocument()->getName(),
|
||||
obj->getNameInDocument(),
|
||||
subs
|
||||
);
|
||||
}
|
||||
else {
|
||||
Gui::Selection().addSelection(
|
||||
obj->getDocument()->getName(),
|
||||
obj->getNameInDocument()
|
||||
);
|
||||
}
|
||||
}
|
||||
Gui::Selection().selStackPush();
|
||||
break;
|
||||
}
|
||||
Gui::Selection().selStackPush();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return ViewProviderPart::setEdit(ModNum);
|
||||
default:
|
||||
return ViewProviderPart::setEdit(ModNum);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {
|
||||
void ViewProviderSubShapeBinder::updatePlacement(bool transaction)
|
||||
{
|
||||
auto self = getObject<PartDesign::SubShapeBinder>();
|
||||
if (!self || !self->Support.getValue())
|
||||
if (!self || !self->Support.getValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Base::Matrix4D> mats;
|
||||
bool relative = self->Relative.getValue();
|
||||
@@ -364,9 +411,8 @@ void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {
|
||||
std::string parentSub;
|
||||
if (relative && !self->getParents().empty()) {
|
||||
const auto& sel = Gui::Selection().getSelection("", Gui::ResolveMode::NoResolve);
|
||||
if (sel.size() != 1 || !sel[0].pObject ||
|
||||
sel[0].pObject->getSubObject(sel[0].SubName) != self)
|
||||
{
|
||||
if (sel.size() != 1 || !sel[0].pObject
|
||||
|| sel[0].pObject->getSubObject(sel[0].SubName) != self) {
|
||||
FC_WARN("invalid selection");
|
||||
}
|
||||
else {
|
||||
@@ -376,8 +422,9 @@ void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {
|
||||
}
|
||||
|
||||
if (!transaction) {
|
||||
if (relative)
|
||||
if (relative) {
|
||||
self->Context.setValue(parent, parentSub.c_str());
|
||||
}
|
||||
try {
|
||||
self->update(PartDesign::SubShapeBinder::UpdateForced);
|
||||
}
|
||||
@@ -389,8 +436,9 @@ void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {
|
||||
|
||||
App::GetApplication().setActiveTransaction("Sync binder");
|
||||
try {
|
||||
if (relative)
|
||||
if (relative) {
|
||||
self->Context.setValue(parent, parentSub.c_str());
|
||||
}
|
||||
self->update(PartDesign::SubShapeBinder::UpdateForced);
|
||||
App::GetApplication().closeActiveTransaction();
|
||||
return;
|
||||
@@ -402,32 +450,40 @@ void ViewProviderSubShapeBinder::updatePlacement(bool transaction) {
|
||||
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() const {
|
||||
std::vector<App::DocumentObject*> ViewProviderSubShapeBinder::claimChildren() const
|
||||
{
|
||||
std::vector<App::DocumentObject*> ret;
|
||||
auto self = freecad_cast<PartDesign::SubShapeBinder*>(getObject());
|
||||
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)
|
||||
if (objSet.insert(obj).second) {
|
||||
ret.push_back(obj);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,8 +492,11 @@ std::vector<App::DocumentObject*> ViewProviderSubShapeBinder::claimChildren() co
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Gui {
|
||||
PROPERTY_SOURCE_TEMPLATE(PartDesignGui::ViewProviderSubShapeBinderPython,
|
||||
PartDesignGui::ViewProviderSubShapeBinder)
|
||||
namespace Gui
|
||||
{
|
||||
PROPERTY_SOURCE_TEMPLATE(
|
||||
PartDesignGui::ViewProviderSubShapeBinderPython,
|
||||
PartDesignGui::ViewProviderSubShapeBinder
|
||||
)
|
||||
template class PartDesignGuiExport ViewProviderFeaturePythonT<ViewProviderSubShapeBinder>;
|
||||
}
|
||||
} // namespace Gui
|
||||
|
||||
Reference in New Issue
Block a user