add new option <parent> in command <open>

This commit is contained in:
theadib
2020-12-29 21:04:03 +01:00
parent fd745155ee
commit 932ea1b449
5 changed files with 75 additions and 3 deletions
+4
View File
@@ -1,7 +1,11 @@
gJsonRPCPlugin versions
2020-12-29 1.2
add option <parent> in command <open> to specify position in object tree
2020-12-29 1.1
add option <name> in command <open> to specify name caption in CC treeview
Fix compilation with the stereo version of CC
2020-12-29 1.0
add command <version> to get version information
+2 -1
View File
@@ -86,7 +86,8 @@ interface
filter: string, optional, filter identificator, if not given then CloudCompare identifies fileformat based on extension
silent: bool, optional, if true, then filterdialog is suppressed
transformation: list of float (16values), optional, after import this transformation matrix is applied to the object,
name: specify name in CC object treeview
name: specify caption name in CC object treeview
parent: specify position in CC object treeview, parent names are separated by "/"
- clear - clear all objects
- version - return version number of plugin
```
+4 -1
View File
@@ -42,7 +42,10 @@ public slots:
private:
//! Default action
QAction* m_action{nullptr};
const QString version{"1.1"};
const QString version{"1.2"};
QString recursiveName(ccHObject *);
ccHObject *createParent(QString path);
protected:
/// server that emit the execute signals
JsonRPCServer rpc_server;
+64
View File
@@ -152,6 +152,16 @@ JsonRPCResult JsonRPCPlugin::execute(QString method, QMap<QString, QVariant> par
newGroup->setName(objname);
}
QString parentname = params["parent"].toString().trimmed();
if(!parentname.isEmpty())
{
auto parent = createParent(parentname);
if(parent)
{
parent->addChild(newGroup);
}
}
m_app->addToDB(newGroup);
need_redraw = true;
result = JsonRPCResult::success(0);
@@ -190,3 +200,57 @@ JsonRPCResult JsonRPCPlugin::execute(QString method, QMap<QString, QVariant> par
return result;
}
// concatenate the names recursively
QString JsonRPCPlugin::recursiveName(ccHObject *obj)
{
QString name;
while(obj) {
name.prepend(obj->getName()+"/");
obj = obj->getParent();
}
return name;
}
// select objects along the path and create if not existing
ccHObject *JsonRPCPlugin::createParent(QString path)
{
QStringList tokens = path.split("/");
qDebug() << "createParent() " << path << tokens;
auto parent = m_app->dbRootObject();
while(!tokens.isEmpty() && parent)
{
if(!tokens.first().trimmed().isEmpty())
{
ccHObject *next{nullptr};
ccHObject::Container filteredChildren;
parent->filterChildren(filteredChildren, false, CC_TYPES::HIERARCHY_OBJECT, true);
for(const auto &child: filteredChildren)
{
qDebug() << "iterate name:" << child->getName() << ", type:" << child->getClassID() << " recursive: " << recursiveName(child);
if(child->getName().compare(tokens.first().trimmed(), Qt::CaseInsensitive) == 0) {
// name matches
next = child;
break;
}
}
if(!next)
{
// not found; create one
next = new ccHObject(tokens.first().trimmed());
if(!next) {
return parent;
}
parent->addChild(next);
m_app->addToDB(next);
}
parent = next;
}
tokens.removeFirst();
}
return parent;
}
+1 -1
View File
@@ -6,7 +6,7 @@ import websockets
async def hello():
uri = "ws://localhost:6001"
async with websockets.connect(uri) as websocket:
await websocket.send('{"jsonrpc": "2.0", "method": "open", "params": {"filename": "/home/adib/Dokumente/teapot.ply", "filter":"PLY mesh (*.ply)", "silent":true, "name":"testpod"}, "id": 4}')
await websocket.send('{"jsonrpc": "2.0", "method": "open", "params": {"filename": "/home/adib/Dokumente/teapot.ply", "filter":"PLY mesh (*.ply)", "silent":true, "name":"testpod", "parent":"one/two/three"}, "id": 4}')
result = await websocket.recv()
print("result: ", result)