43#include "MergePlugin.hh"
50#include <QInputDialog>
57 template<
class MeshT >
58 void getAllMeshes(std::vector< MeshT* > & meshes,
const std::vector< BaseObjectData* > & objects)
60 for (uint i=0; i <
objects.size(); i++)
64 meshes.push_back( t );
68 void getTargets(std::vector< BaseObjectData* > & _objects)
73 _objects.push_back( o_it );
76 template<
class MeshT >
77 void convertMeshes(
const DataType & _type, std::vector< int >& convertedIds, std::vector< MeshT* >& _meshes)
82 convertedIds.push_back(RPC::callFunctionValue<int>(
"meshconvert",
"convert",o_it->id(), _type !=
DATA_TRIANGLE_MESH));
85 _meshes.push_back(ptr);
97 for(
int i : convertedIds)
98 emit deleteObject( i );
100 convertedIds.clear();
102 if(_deleteSeparateObjects)
105 for (
size_t i=0; i < objects.size(); i++)
106 emit deleteObject( (objects[i])->
id() );
112 emit deleteObject( polyMergeID );
114 emit deleteObject( triMergeID );
117DataType MergePlugin::checkType(
const std::vector< BaseObjectData* > & objects )
119 DataType type = (objects[0])->dataType();
120 bool askForType =
false;
121 for (uint i=1; i < objects.size(); i++)
122 if ( type != (objects[i])->dataType() ){
133 QString result = QInputDialog::getItem(
nullptr,
134 tr(
"Select Mesh Type"),
135 tr(
"Convert meshes to:"),
158MergePlugin::MergePlugin() :
167MergePlugin::~MergePlugin() {
173 if ( ! OpenFlipper::Options::gui())
177 QSize size(300, 300);
180 connect(tool_->mergeButton, SIGNAL( clicked() ),
this, SLOT(
mergeObjects() ) );
181 tool_->mergeButton->setStatusTip(
"Merge all target objects into one without changing geometry");
182 tool_->mergeButton->setToolTip( tool_->mergeButton->statusTip() );
183 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"merge.png");
187 emit addToolbox( tr(
"Merge") , tool_, toolIcon_ );
190void MergePlugin::pluginsInitialized()
193 emit setSlotDescription(
"mergeObjects(const std::vector< BaseObjectData* >,QString,bool,DataType)",
"Merges multiple meshes into one mesh. returns the ID of the new mesh or -1 in case of error.",
194 QString(
"objects,mergedName,deleteSeparateObjects").split(
","),
195 QString(
" vector of BaseObjectData* containing Poly or TriMeshes to be merged, name for the merged object, flag to remove separated objects default is true, DataType for the new mesh if used in nogui mode").split(
","));
197 emit setSlotDescription(
"mergeObjects(IdList,QString,bool,DataType)",
"Merges multiple meshes into one mesh. returns the ID of the new mesh or -1 in case of error.",
198 QString(
"objects,mergedName,deleteSeparateObjects").split(
","),
199 QString(
" vector of Object Ids of Poly or TriMeshes to be merged, name for the merged object, flag to remove separated objects default is true, DataType for the new mesh if used in nogui mode").split(
","));
204 std::vector< BaseObjectData* > objects;
205 for(
int i : _objects)
211 return mergeObjects(objects, _name, _deleteSeparateObjects, _type);
217 if (_objects.size() < 2)
223 if ( OpenFlipper::Options::gui())
224 type = checkType(objects);
232 convertedIds.clear();
233 std::vector< TriMesh* > triMeshes;
234 std::vector< PolyMesh* > polyMeshes;
235 TriMesh* triMergePtr;
236 PolyMesh* polyMergePtr;
240 polyMeshes.push_back(polyMergePtr);
243 triMeshes.push_back(triMergePtr);
245 getAllMeshes(triMeshes,objects);
246 getAllMeshes(polyMeshes,objects);
253 (triMeshes[0])->update_normals();
263 (polyMeshes[0])->update_normals();
274 emit cleanup( type, _deleteSeparateObjects );
282 mergeObjects(objects,tool_->mergedName->text(),tool_->deleteObjects->isChecked());
DLLEXPORT QString dataTypeName(DataType _id)
Get DataType Human readable name ( this name might change. Use the typeName instead!...
std::vector< int > IdList
Standard Type for id Lists used for scripting.
#define DATA_TRIANGLE_MESH
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void mergeMeshes(const std::vector< MeshT * > &_meshes)
merges Meshes into the first mesh
void slotCleanup(DataType _type, bool _deleteSeparateObjects)
slotCleanup is called when the cleanup event is processed at the end of mergeObjects.
void initializePlugin()
init the Toolbox
void mergeObjects()
merge two objects with target flag
virtual void clear(bool _clearProps=true)
Clear whole mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
bool getAllMeshes(std::vector< int > &_identifiers)
Get identifiers of all meshes.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
BaseObjectData * baseObjectData(BaseObject *_object)
Cast an BaseObject to a BaseObjectData if possible.