All: Reformat according to new standard
This commit is contained in:
committed by
Kacper Donat
parent
ef997f2259
commit
9fe130cd73
@@ -21,21 +21,20 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
# include <Inventor/actions/SoGetBoundingBoxAction.h>
|
||||
# include <Inventor/details/SoFaceDetail.h>
|
||||
# include <Inventor/details/SoLineDetail.h>
|
||||
# include <Inventor/details/SoPointDetail.h>
|
||||
# include <Inventor/nodes/SoDrawStyle.h>
|
||||
# include <Inventor/nodes/SoMaterial.h>
|
||||
# include <Inventor/nodes/SoMaterialBinding.h>
|
||||
# include <Inventor/nodes/SoPickStyle.h>
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
# include <Inventor/nodes/SoShapeHints.h>
|
||||
# include <Precision.hxx>
|
||||
# include <QMessageBox>
|
||||
# include <QAction>
|
||||
# include <QMenu>
|
||||
#include <Inventor/actions/SoGetBoundingBoxAction.h>
|
||||
#include <Inventor/details/SoFaceDetail.h>
|
||||
#include <Inventor/details/SoLineDetail.h>
|
||||
#include <Inventor/details/SoPointDetail.h>
|
||||
#include <Inventor/nodes/SoDrawStyle.h>
|
||||
#include <Inventor/nodes/SoMaterial.h>
|
||||
#include <Inventor/nodes/SoMaterialBinding.h>
|
||||
#include <Inventor/nodes/SoPickStyle.h>
|
||||
#include <Inventor/nodes/SoSeparator.h>
|
||||
#include <Inventor/nodes/SoShapeHints.h>
|
||||
#include <Precision.hxx>
|
||||
#include <QMessageBox>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
|
||||
|
||||
#include <App/Document.h>
|
||||
@@ -61,10 +60,10 @@
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE_WITH_EXTENSIONS(PartDesignGui::ViewProviderDatum,Gui::ViewProviderGeometryObject)
|
||||
PROPERTY_SOURCE_WITH_EXTENSIONS(PartDesignGui::ViewProviderDatum, Gui::ViewProviderGeometryObject)
|
||||
|
||||
// static data
|
||||
const double ViewProviderDatum::defaultSize = Gui::ViewProviderCoordinateSystem::defaultSize ();
|
||||
const double ViewProviderDatum::defaultSize = Gui::ViewProviderCoordinateSystem::defaultSize();
|
||||
|
||||
ViewProviderDatum::ViewProviderDatum()
|
||||
{
|
||||
@@ -78,14 +77,15 @@ ViewProviderDatum::ViewProviderDatum()
|
||||
DisplayMode.setStatus(App::Property::Hidden, true);
|
||||
|
||||
// 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 );
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/PartDesign"
|
||||
);
|
||||
unsigned long shcol = hGrp->GetUnsigned("DefaultDatumColor", 0xFFD70099);
|
||||
|
||||
Base::Color col ( (uint32_t) shcol );
|
||||
Base::Color col((uint32_t)shcol);
|
||||
ShapeAppearance.setDiffuseColor(col);
|
||||
|
||||
Transparency.setValue (col.a * 100);
|
||||
Transparency.setValue(col.a * 100);
|
||||
|
||||
oldWb = "";
|
||||
oldTip = nullptr;
|
||||
@@ -97,13 +97,13 @@ ViewProviderDatum::~ViewProviderDatum()
|
||||
pPickStyle->unref();
|
||||
}
|
||||
|
||||
void ViewProviderDatum::attach(App::DocumentObject *obj)
|
||||
void ViewProviderDatum::attach(App::DocumentObject* obj)
|
||||
{
|
||||
if (auto geo = dynamic_cast<App::GeoFeature*>(obj)) {
|
||||
geo->setMaterialAppearance(ShapeAppearance[0]);
|
||||
}
|
||||
|
||||
ViewProviderGeometryObject::attach ( obj );
|
||||
ViewProviderGeometryObject::attach(obj);
|
||||
|
||||
// TODO remove this field (2015-09-08, Fat-Zer)
|
||||
App::DocumentObject* o = getObject();
|
||||
@@ -150,9 +150,10 @@ void ViewProviderDatum::attach(App::DocumentObject *obj)
|
||||
addDisplayMaskMode(sep, "Base");
|
||||
}
|
||||
|
||||
bool ViewProviderDatum::onDelete(const std::vector<std::string> &)
|
||||
bool ViewProviderDatum::onDelete(const std::vector<std::string>&)
|
||||
{
|
||||
// TODO: Ask user what to do about dependent objects, e.g. Sketches that have this feature as their support
|
||||
// TODO: Ask user what to do about dependent objects, e.g. Sketches that have this feature as
|
||||
// their support
|
||||
// 1. Delete
|
||||
// 2. Suppress
|
||||
// 3. Re-route
|
||||
@@ -162,13 +163,14 @@ bool ViewProviderDatum::onDelete(const std::vector<std::string> &)
|
||||
|
||||
std::vector<std::string> ViewProviderDatum::getDisplayModes() const
|
||||
{
|
||||
return { "Base" };
|
||||
return {"Base"};
|
||||
}
|
||||
|
||||
void ViewProviderDatum::setDisplayMode(const char* ModeName)
|
||||
{
|
||||
if (strcmp(ModeName, "Base") == 0)
|
||||
if (strcmp(ModeName, "Base") == 0) {
|
||||
setDisplayMaskMode("Base");
|
||||
}
|
||||
ViewProviderGeometryObject::setDisplayMode(ModeName);
|
||||
}
|
||||
|
||||
@@ -180,16 +182,19 @@ std::string ViewProviderDatum::getElement(const SoDetail* detail) const
|
||||
if (detail->getTypeId() == SoLineDetail::getClassTypeId()) {
|
||||
const SoLineDetail* line_detail = static_cast<const SoLineDetail*>(detail);
|
||||
element = line_detail->getLineIndex();
|
||||
} else if (detail->getTypeId() == SoFaceDetail::getClassTypeId()) {
|
||||
}
|
||||
else if (detail->getTypeId() == SoFaceDetail::getClassTypeId()) {
|
||||
const SoFaceDetail* face_detail = static_cast<const SoFaceDetail*>(detail);
|
||||
element = face_detail->getFaceIndex();
|
||||
} else if (detail->getTypeId() == SoPointDetail::getClassTypeId()) {
|
||||
}
|
||||
else if (detail->getTypeId() == SoPointDetail::getClassTypeId()) {
|
||||
const SoPointDetail* point_detail = static_cast<const SoPointDetail*>(detail);
|
||||
element = point_detail->getCoordinateIndex();
|
||||
}
|
||||
|
||||
if (element == 0)
|
||||
if (element == 0) {
|
||||
return datumType.toStdString();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
@@ -200,18 +205,20 @@ SoDetail* ViewProviderDatum::getDetail(const char* subelement) const
|
||||
QString subelem = QString::fromLatin1(subelement);
|
||||
|
||||
if (subelem == QObject::tr("Line")) {
|
||||
SoLineDetail* detail = new SoLineDetail();
|
||||
detail->setPartIndex(0);
|
||||
return detail;
|
||||
} else if (subelem == QObject::tr("Plane")) {
|
||||
SoLineDetail* detail = new SoLineDetail();
|
||||
detail->setPartIndex(0);
|
||||
return detail;
|
||||
}
|
||||
else if (subelem == QObject::tr("Plane")) {
|
||||
SoFaceDetail* detail = new SoFaceDetail();
|
||||
detail->setPartIndex(0);
|
||||
return detail;
|
||||
} else if (subelem == QObject::tr("Point")) {
|
||||
}
|
||||
else if (subelem == QObject::tr("Point")) {
|
||||
SoPointDetail* detail = new SoPointDetail();
|
||||
detail->setCoordinateIndex(0);
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -232,17 +239,19 @@ void ViewProviderDatum::setupContextMenu(QMenu* menu, QObject* receiver, const c
|
||||
|
||||
bool ViewProviderDatum::setEdit(int ModNum)
|
||||
{
|
||||
if (!ViewProvider::setEdit(ModNum))
|
||||
if (!ViewProvider::setEdit(ModNum)) {
|
||||
return false;
|
||||
}
|
||||
// TODO Share this code with Features view providers somehow (2015-09-08, Fat-Zer)
|
||||
if (ModNum == ViewProvider::Default ) {
|
||||
if (ModNum == ViewProvider::Default) {
|
||||
// When double-clicking on the item for this datum feature the
|
||||
// object unsets and sets its edit mode without closing
|
||||
// the task panel
|
||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
||||
TaskDlgDatumParameters *datumDlg = qobject_cast<TaskDlgDatumParameters *>(dlg);
|
||||
if (datumDlg && datumDlg->getViewProvider() != this)
|
||||
datumDlg = nullptr; // another datum feature left open its task panel
|
||||
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
|
||||
TaskDlgDatumParameters* datumDlg = qobject_cast<TaskDlgDatumParameters*>(dlg);
|
||||
if (datumDlg && datumDlg->getViewProvider() != this) {
|
||||
datumDlg = nullptr; // another datum feature left open its task panel
|
||||
}
|
||||
if (dlg && !datumDlg) {
|
||||
QMessageBox msgBox(Gui::getMainWindow());
|
||||
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
|
||||
@@ -250,10 +259,12 @@ bool ViewProviderDatum::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().closeDialog();
|
||||
else
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// clear the selection (convenience)
|
||||
@@ -262,10 +273,12 @@ bool ViewProviderDatum::setEdit(int ModNum)
|
||||
oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench");
|
||||
|
||||
// start the edit dialog
|
||||
if (datumDlg)
|
||||
if (datumDlg) {
|
||||
Gui::Control().showDialog(datumDlg);
|
||||
else
|
||||
}
|
||||
else {
|
||||
Gui::Control().showDialog(new TaskDlgDatumParameters(this));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -277,11 +290,13 @@ bool ViewProviderDatum::setEdit(int ModNum)
|
||||
bool ViewProviderDatum::doubleClicked()
|
||||
{
|
||||
auto activeDoc = Gui::Application::Instance->activeDocument();
|
||||
if(!activeDoc)
|
||||
if (!activeDoc) {
|
||||
activeDoc = getDocument();
|
||||
}
|
||||
auto activeView = activeDoc->getActiveView();
|
||||
if(!activeView)
|
||||
if (!activeView) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Msg("Edit ");
|
||||
Msg += this->pcObject->Label.getValue();
|
||||
@@ -293,13 +308,16 @@ bool ViewProviderDatum::doubleClicked()
|
||||
|
||||
if (datumBody) {
|
||||
if (datumBody != activeBody) {
|
||||
Gui::Command::doCommand(Gui::Command::Gui,
|
||||
"Gui.ActiveDocument.ActiveView.setActiveObject('%s',%s)",
|
||||
PDBODYKEY, Gui::Command::getObjectCmd(datumBody).c_str());
|
||||
Gui::Command::doCommand(
|
||||
Gui::Command::Gui,
|
||||
"Gui.ActiveDocument.ActiveView.setActiveObject('%s',%s)",
|
||||
PDBODYKEY,
|
||||
Gui::Command::getObjectCmd(datumBody).c_str()
|
||||
);
|
||||
activeBody = datumBody;
|
||||
}
|
||||
}
|
||||
return PartDesignGui::setEdit(pcObject,activeBody);
|
||||
return PartDesignGui::setEdit(pcObject, activeBody);
|
||||
}
|
||||
|
||||
void ViewProviderDatum::unsetEdit(int ModNum)
|
||||
@@ -316,75 +334,97 @@ void ViewProviderDatum::unsetEdit(int ModNum)
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderDatum::updateExtents () {
|
||||
setExtents ( getRelevantBoundBox () );
|
||||
void ViewProviderDatum::updateExtents()
|
||||
{
|
||||
setExtents(getRelevantBoundBox());
|
||||
}
|
||||
|
||||
void ViewProviderDatum::setExtents (const SbBox3f &bbox) {
|
||||
const SbVec3f & min = bbox.getMin ();
|
||||
const SbVec3f & max = bbox.getMax ();
|
||||
setExtents ( Base::BoundBox3d ( min.getValue()[0], min.getValue()[1], min.getValue()[2],
|
||||
max.getValue()[0], max.getValue()[1], max.getValue()[2] ) );
|
||||
void ViewProviderDatum::setExtents(const SbBox3f& bbox)
|
||||
{
|
||||
const SbVec3f& min = bbox.getMin();
|
||||
const SbVec3f& max = bbox.getMax();
|
||||
setExtents(
|
||||
Base::BoundBox3d(
|
||||
min.getValue()[0],
|
||||
min.getValue()[1],
|
||||
min.getValue()[2],
|
||||
max.getValue()[0],
|
||||
max.getValue()[1],
|
||||
max.getValue()[2]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
SbBox3f ViewProviderDatum::getRelevantBoundBox () const {
|
||||
std::vector<App::DocumentObject *> objs;
|
||||
SbBox3f ViewProviderDatum::getRelevantBoundBox() const
|
||||
{
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
|
||||
// Probe body first
|
||||
PartDesign::Body* body = PartDesign::Body::findBodyOf ( this->getObject() );
|
||||
PartDesign::Body* body = PartDesign::Body::findBodyOf(this->getObject());
|
||||
if (body) {
|
||||
objs = body->getFullModel ();
|
||||
} else {
|
||||
objs = body->getFullModel();
|
||||
}
|
||||
else {
|
||||
// Probe if we belongs to some group
|
||||
App::DocumentObject* group = App::DocumentObjectGroup::getGroupOfObject ( this->getObject () );
|
||||
App::DocumentObject* group = App::DocumentObjectGroup::getGroupOfObject(this->getObject());
|
||||
|
||||
if(group) {
|
||||
if (group) {
|
||||
auto* ext = group->getExtensionByType<App::GroupExtension>();
|
||||
if(ext)
|
||||
objs = ext->getObjects ();
|
||||
} else {
|
||||
if (ext) {
|
||||
objs = ext->getObjects();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Fallback to whole document
|
||||
objs = this->getObject ()->getDocument ()->getObjects ();
|
||||
objs = this->getObject()->getDocument()->getObjects();
|
||||
}
|
||||
}
|
||||
|
||||
Gui::View3DInventor* view = dynamic_cast<Gui::View3DInventor*>(this->getActiveView());
|
||||
if(view){
|
||||
Gui::View3DInventorViewer* viewer = view->getViewer();
|
||||
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion());
|
||||
SbBox3f bbox = getRelevantBoundBox (bboxAction, objs);
|
||||
if (view) {
|
||||
Gui::View3DInventorViewer* viewer = view->getViewer();
|
||||
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion());
|
||||
SbBox3f bbox = getRelevantBoundBox(bboxAction, objs);
|
||||
|
||||
if ( bbox.getVolume () < Precision::Confusion() ) {
|
||||
bbox.extendBy ( defaultBoundBox () );
|
||||
}
|
||||
return bbox;
|
||||
} else {
|
||||
return defaultBoundBox();
|
||||
if (bbox.getVolume() < Precision::Confusion()) {
|
||||
bbox.extendBy(defaultBoundBox());
|
||||
}
|
||||
return bbox;
|
||||
}
|
||||
else {
|
||||
return defaultBoundBox();
|
||||
}
|
||||
}
|
||||
|
||||
SbBox3f ViewProviderDatum::getRelevantBoundBox (
|
||||
SoGetBoundingBoxAction &bboxAction, const std::vector <App::DocumentObject *> &objs )
|
||||
SbBox3f ViewProviderDatum::getRelevantBoundBox(
|
||||
SoGetBoundingBoxAction& bboxAction,
|
||||
const std::vector<App::DocumentObject*>& objs
|
||||
)
|
||||
{
|
||||
SbBox3f bbox = defaultBoundBox();
|
||||
|
||||
// Adds the bbox of given feature to the output
|
||||
for (auto obj :objs) {
|
||||
ViewProvider *vp = Gui::Application::Instance->getViewProvider(obj);
|
||||
if (!vp) { continue; }
|
||||
if (!vp->isVisible ()) { continue; }
|
||||
for (auto obj : objs) {
|
||||
ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj);
|
||||
if (!vp) {
|
||||
continue;
|
||||
}
|
||||
if (!vp->isVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (obj->isDerivedFrom (Part::Datum::getClassTypeId() ) ) {
|
||||
if (obj->isDerivedFrom(Part::Datum::getClassTypeId())) {
|
||||
// Treat datums only as their basepoint
|
||||
// I hope it's ok to take FreeCAD's point here
|
||||
Base::Vector3d basePoint = static_cast<Part::Datum *> ( obj )->getBasePoint ();
|
||||
bbox.extendBy (SbVec3f(basePoint.x, basePoint.y, basePoint.z ));
|
||||
} else {
|
||||
bboxAction.apply ( vp->getRoot () );
|
||||
SbBox3f obj_bbox = bboxAction.getBoundingBox ();
|
||||
Base::Vector3d basePoint = static_cast<Part::Datum*>(obj)->getBasePoint();
|
||||
bbox.extendBy(SbVec3f(basePoint.x, basePoint.y, basePoint.z));
|
||||
}
|
||||
else {
|
||||
bboxAction.apply(vp->getRoot());
|
||||
SbBox3f obj_bbox = bboxAction.getBoundingBox();
|
||||
|
||||
if ( obj_bbox.getVolume () < Precision::Infinite () ) {
|
||||
bbox.extendBy ( obj_bbox );
|
||||
if (obj_bbox.getVolume() < Precision::Infinite()) {
|
||||
bbox.extendBy(obj_bbox);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,20 +433,24 @@ SbBox3f ViewProviderDatum::getRelevantBoundBox (
|
||||
return bbox;
|
||||
}
|
||||
|
||||
SbBox3f ViewProviderDatum::defaultBoundBox () {
|
||||
return SbBox3f ( -defaultSize, -defaultSize, -defaultSize,
|
||||
defaultSize, defaultSize, defaultSize );
|
||||
SbBox3f ViewProviderDatum::defaultBoundBox()
|
||||
{
|
||||
return SbBox3f(-defaultSize, -defaultSize, -defaultSize, defaultSize, defaultSize, defaultSize);
|
||||
}
|
||||
|
||||
bool ViewProviderDatum::isPickable() {
|
||||
bool ViewProviderDatum::isPickable()
|
||||
{
|
||||
|
||||
return bool(pPickStyle->style.getValue() == SoPickStyle::SHAPE);
|
||||
}
|
||||
|
||||
void ViewProviderDatum::setPickable(bool val) {
|
||||
void ViewProviderDatum::setPickable(bool val)
|
||||
{
|
||||
|
||||
if(val)
|
||||
if (val) {
|
||||
pPickStyle->style = SoPickStyle::SHAPE;
|
||||
else
|
||||
}
|
||||
else {
|
||||
pPickStyle->style = SoPickStyle::UNPICKABLE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user