mirror of
https://gitlab.com/theadib/JSonRPCPlugin.git
synced 2026-08-29 15:40:24 +08:00
add new option <parent> in command <open>
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
gJsonRPCPlugin versions
|
gJsonRPCPlugin versions
|
||||||
|
|
||||||
|
2020-12-29 1.2
|
||||||
|
add option <parent> in command <open> to specify position in object tree
|
||||||
|
|
||||||
2020-12-29 1.1
|
2020-12-29 1.1
|
||||||
add option <name> in command <open> to specify name caption in CC treeview
|
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
|
2020-12-29 1.0
|
||||||
add command <version> to get version information
|
add command <version> to get version information
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ interface
|
|||||||
filter: string, optional, filter identificator, if not given then CloudCompare identifies fileformat based on extension
|
filter: string, optional, filter identificator, if not given then CloudCompare identifies fileformat based on extension
|
||||||
silent: bool, optional, if true, then filterdialog is suppressed
|
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,
|
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
|
- clear - clear all objects
|
||||||
- version - return version number of plugin
|
- version - return version number of plugin
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -42,7 +42,10 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
//! Default action
|
//! Default action
|
||||||
QAction* m_action{nullptr};
|
QAction* m_action{nullptr};
|
||||||
const QString version{"1.1"};
|
const QString version{"1.2"};
|
||||||
|
|
||||||
|
QString recursiveName(ccHObject *);
|
||||||
|
ccHObject *createParent(QString path);
|
||||||
protected:
|
protected:
|
||||||
/// server that emit the execute signals
|
/// server that emit the execute signals
|
||||||
JsonRPCServer rpc_server;
|
JsonRPCServer rpc_server;
|
||||||
|
|||||||
@@ -152,6 +152,16 @@ JsonRPCResult JsonRPCPlugin::execute(QString method, QMap<QString, QVariant> par
|
|||||||
newGroup->setName(objname);
|
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);
|
m_app->addToDB(newGroup);
|
||||||
need_redraw = true;
|
need_redraw = true;
|
||||||
result = JsonRPCResult::success(0);
|
result = JsonRPCResult::success(0);
|
||||||
@@ -190,3 +200,57 @@ JsonRPCResult JsonRPCPlugin::execute(QString method, QMap<QString, QVariant> par
|
|||||||
|
|
||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import websockets
|
|||||||
async def hello():
|
async def hello():
|
||||||
uri = "ws://localhost:6001"
|
uri = "ws://localhost:6001"
|
||||||
async with websockets.connect(uri) as websocket:
|
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()
|
result = await websocket.recv()
|
||||||
print("result: ", result)
|
print("result: ", result)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user