feat(model): added model container object for parts
This commit is contained in:
parent
497a3f783c
commit
19b6489476
6 changed files with 101 additions and 1 deletions
BIN
assets/icons/model.png
Normal file
BIN
assets/icons/model.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 825 B |
|
@ -5,6 +5,7 @@
|
|||
#include "objects/joint/rotatev.h"
|
||||
#include "objects/joint/weld.h"
|
||||
#include "objects/jointsservice.h"
|
||||
#include "objects/model.h"
|
||||
#include "objects/part.h"
|
||||
#include "objects/joint/snap.h"
|
||||
#include "objects/script.h"
|
||||
|
@ -24,7 +25,8 @@ std::map<std::string, const InstanceType*> INSTANCE_MAP = {
|
|||
{ "RotateV", &RotateV::TYPE },
|
||||
{ "JointInstance", &JointInstance::TYPE },
|
||||
{ "Script", &Script::TYPE },
|
||||
{ "Folder", &Folder::TYPE },
|
||||
{ "Model", &Model::TYPE },
|
||||
// { "Folder", &Folder::TYPE },
|
||||
|
||||
// Services
|
||||
|
||||
|
|
4
core/src/objects/model.cpp
Normal file
4
core/src/objects/model.cpp
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include "model.h"
|
||||
|
||||
Model::Model(): Instance(&TYPE) {}
|
||||
Model::~Model() = default;
|
18
core/src/objects/model.h
Normal file
18
core/src/objects/model.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include <memory>
|
||||
|
||||
// Group object for Parts
|
||||
|
||||
class DEF_INST_(explorer_icon="model") Model : public Instance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
public:
|
||||
Model();
|
||||
~Model();
|
||||
|
||||
static inline std::shared_ptr<Model> New() { return std::make_shared<Model>(); };
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<Model>(); };
|
||||
};
|
|
@ -3,6 +3,7 @@
|
|||
#include "common.h"
|
||||
#include "logger.h"
|
||||
#include "objects/datamodel.h"
|
||||
#include "objects/model.h"
|
||||
#include "placedocument.h"
|
||||
#include "script/scriptdocument.h"
|
||||
#include <cstdio>
|
||||
|
@ -19,6 +20,7 @@
|
|||
#include <pugixml.hpp>
|
||||
#include <qtextcursor.h>
|
||||
#include <qtextedit.h>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _NDEBUG
|
||||
#define NDEBUG
|
||||
|
@ -364,6 +366,44 @@ void MainWindow::connectActionHandlers() {
|
|||
}
|
||||
});
|
||||
|
||||
connect(ui->actionGroupObjects, &QAction::triggered, this, [&]() {
|
||||
auto model = Model::New();
|
||||
std::shared_ptr<Instance> firstParent;
|
||||
|
||||
for (auto object : getSelection()) {
|
||||
if (firstParent == nullptr && object->GetParent().has_value()) firstParent = object->GetParent().value();
|
||||
object->SetParent(model);
|
||||
}
|
||||
|
||||
if (model->GetChildren().size() == 0)
|
||||
return;
|
||||
|
||||
// Technically not how it works in the actual studio, but it's not an API-breaking change
|
||||
// and I think this implementation is more useful so I'm sticking with it
|
||||
if (firstParent == nullptr) firstParent = gWorkspace();
|
||||
model->SetParent(firstParent);
|
||||
|
||||
setSelection({ model });
|
||||
});
|
||||
|
||||
connect(ui->actionUngroupObjects, &QAction::triggered, this, [&]() {
|
||||
std::vector<std::shared_ptr<Instance>> newSelection;
|
||||
|
||||
for (auto model : getSelection()) {
|
||||
// Not a model, skip
|
||||
if (!model->IsA<Model>()) { newSelection.push_back(model); continue; }
|
||||
|
||||
for (auto object : model->GetChildren()) {
|
||||
object->SetParent(model->GetParent());
|
||||
newSelection.push_back(object);
|
||||
}
|
||||
|
||||
model->Destroy();
|
||||
}
|
||||
|
||||
setSelection(newSelection);
|
||||
});
|
||||
|
||||
connect(ui->actionSaveModel, &QAction::triggered, this, [&]() {
|
||||
std::optional<std::string> path = openFileDialog("Openblocks Model (*.obm)", ".obm", QFileDialog::AcceptSave);
|
||||
if (!path) return;
|
||||
|
|
|
@ -176,6 +176,8 @@
|
|||
<addaction name="actionCut"/>
|
||||
<addaction name="actionPaste"/>
|
||||
<addaction name="actionPasteInto"/>
|
||||
<addaction name="actionGroupObjects"/>
|
||||
<addaction name="actionUngroupObjects"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="snappingOptions">
|
||||
<property name="windowTitle">
|
||||
|
@ -768,6 +770,40 @@
|
|||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionGroupObjects">
|
||||
<property name="icon">
|
||||
<iconset theme="object-group"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Group Objects</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Group objects under a Model</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+G</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUngroupObjects">
|
||||
<property name="icon">
|
||||
<iconset theme="object-ungroup"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ungroup Objects</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Ungroup objects inside selected Model</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+U</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
Loading…
Add table
Reference in a new issue