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)
74 _objects.push_back( *o_it );
77 template<
class MeshT >
78 void convertMeshes(
const DataType & _type, std::vector< int >& convertedIds, std::vector< MeshT* >& _meshes)
84 convertedIds.push_back(RPC::callFunctionValue<int>(
"meshconvert",
"convert",(*o_it)->id(), _type !=
DATA_TRIANGLE_MESH));
87 _meshes.push_back(ptr);
99 for(
int i : convertedIds)
100 emit deleteObject( i );
102 convertedIds.clear();
104 if(_deleteSeparateObjects)
107 for (
size_t i=0; i < objects.size(); i++)
108 emit deleteObject( (objects[i])->id() );
114 emit deleteObject( polyMergeID );
116 emit deleteObject( triMergeID );
119 DataType MergePlugin::checkType(
const std::vector< BaseObjectData* > & objects )
121 DataType type = (objects[0])->dataType();
122 bool askForType =
false;
123 for (uint i=1; i < objects.size(); i++)
124 if ( type != (objects[i])->dataType() ){
135 QString result = QInputDialog::getItem(
nullptr,
136 tr(
"Select Mesh Type"),
137 tr(
"Convert meshes to:"),
160 MergePlugin::MergePlugin() :
170 if ( ! OpenFlipper::Options::gui())
174 QSize size(300, 300);
177 connect(tool_->mergeButton, SIGNAL( clicked() ),
this, SLOT(
mergeObjects() ) );
178 tool_->mergeButton->setStatusTip(
"Merge all target objects into one without changing geometry");
179 tool_->mergeButton->setToolTip( tool_->mergeButton->statusTip() );
180 QIcon* toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"merge.png");
184 emit addToolbox( tr(
"Merge") , tool_, toolIcon_ );
187 void MergePlugin::pluginsInitialized()
190 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.",
191 QString(
"objects,mergedName,deleteSeparateObjects").split(
","),
192 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(
","));
194 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.",
195 QString(
"objects,mergedName,deleteSeparateObjects").split(
","),
196 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(
","));
201 std::vector< BaseObjectData* > objects;
202 for(
int i : _objects)
208 return mergeObjects(objects, _name, _deleteSeparateObjects, _type);
214 if (_objects.size() < 2)
220 if ( OpenFlipper::Options::gui())
221 type = checkType(objects);
229 convertedIds.clear();
230 std::vector< TriMesh* > triMeshes;
231 std::vector< PolyMesh* > polyMeshes;
232 TriMesh* triMergePtr;
233 PolyMesh* polyMergePtr;
237 polyMeshes.push_back(polyMergePtr);
240 triMeshes.push_back(triMergePtr);
242 getAllMeshes(triMeshes,objects);
243 getAllMeshes(polyMeshes,objects);
249 *triMergePtr = *triMeshes[1];
251 (triMeshes[0])->update_normals();
260 *polyMergePtr = *polyMeshes[1];
262 (polyMeshes[0])->update_normals();
273 emit cleanup( type, _deleteSeparateObjects );
281 mergeObjects(objects,tool_->mergedName->text(),tool_->deleteObjects->isChecked());
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void initializePlugin()
init the Toolbox
void mergeMeshes(const std::vector< MeshT * > &_meshes)
merges Meshes into the first mesh
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void slotCleanup(DataType _type, bool _deleteSeparateObjects)
slotCleanup is called when the cleanup event is processed at the end of mergeObjects.
void mergeObjects()
merge two objects with target flag
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.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
BaseObjectData * baseObjectData(BaseObject *_object)
Cast an BaseObject to a BaseObjectData if possible.
bool getAllMeshes(std::vector< int > &_identifiers)
Get identifiers of all meshes.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
#define DATA_TRIANGLE_MESH
DLLEXPORT QString dataTypeName(DataType _id)
Get DataType Human readable name ( this name might change. Use the typeName instead! ) ...