diff --git a/CHANGELOG b/CHANGELOG index a027be8..5b5b680 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,11 @@ gJsonRPCPlugin versions +2020-12-29 1.2 +add option in command to specify position in object tree + 2020-12-29 1.1 add option in command to specify name caption in CC treeview +Fix compilation with the stereo version of CC 2020-12-29 1.0 add command to get version information diff --git a/README.md b/README.md index 411bdd6..b89e86d 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/include/JsonRPCPlugin.h b/include/JsonRPCPlugin.h index b167b49..8b264df 100644 --- a/include/JsonRPCPlugin.h +++ b/include/JsonRPCPlugin.h @@ -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; diff --git a/src/JsonRPCPlugin.cpp b/src/JsonRPCPlugin.cpp index ba0e776..03779d3 100644 --- a/src/JsonRPCPlugin.cpp +++ b/src/JsonRPCPlugin.cpp @@ -152,6 +152,16 @@ JsonRPCResult JsonRPCPlugin::execute(QString method, QMap 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 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; +} diff --git a/test/client_open2.py b/test/client_open2.py index 135f525..40d78b5 100755 --- a/test/client_open2.py +++ b/test/client_open2.py @@ -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)