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 );
117 DataType 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:"),
158 MergePlugin::MergePlugin() :
168 if ( ! OpenFlipper::Options::gui())
172 QSize size(300, 300);
175 connect(tool_->mergeButton, SIGNAL( clicked() ),
this, SLOT(
mergeObjects() ) );
176 tool_->mergeButton->setStatusTip(
"Merge all target objects into one without changing geometry");
177 tool_->mergeButton->setToolTip( tool_->mergeButton->statusTip() );
178 QIcon* toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"merge.png");
182 emit addToolbox( tr(
"Merge") , tool_, toolIcon_ );
185 void MergePlugin::pluginsInitialized()
188 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.",
189 QString(
"objects,mergedName,deleteSeparateObjects").split(
","),
190 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(
","));
192 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.",
193 QString(
"objects,mergedName,deleteSeparateObjects").split(
","),
194 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(
","));
199 std::vector< BaseObjectData* > objects;
200 for(
int i : _objects)
206 return mergeObjects(objects, _name, _deleteSeparateObjects, _type);
212 if (_objects.size() < 2)
218 if ( OpenFlipper::Options::gui())
219 type = checkType(objects);
227 convertedIds.clear();
228 std::vector< TriMesh* > triMeshes;
229 std::vector< PolyMesh* > polyMeshes;
230 TriMesh* triMergePtr;
231 PolyMesh* polyMergePtr;
235 polyMeshes.push_back(polyMergePtr);
238 triMeshes.push_back(triMergePtr);
240 getAllMeshes(triMeshes,objects);
241 getAllMeshes(polyMeshes,objects);
248 (triMeshes[0])->update_normals();
258 (polyMeshes[0])->update_normals();
269 emit cleanup( type, _deleteSeparateObjects );
277 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! ) ...
#define DATA_TRIANGLE_MESH
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
BaseObjectData * baseObjectData(BaseObject *_object)
Cast an BaseObject to a BaseObjectData if possible.
bool getAllMeshes(std::vector< int > &_identifiers)
Get identifiers of all meshes.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
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
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void initializePlugin()
init the Toolbox
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
bool getMesh(int _identifier, PolyMesh *&_mesh)
Get the Poly Mesh which has the given identifier.
void mergeObjects()
merge two objects with target flag
void slotCleanup(DataType _type, bool _deleteSeparateObjects)
slotCleanup is called when the cleanup event is processed at the end of mergeObjects.