Assembly: define joint double click on 3dview (#15572)

* Assembly: define joint double click on 3dview

* Update string
This commit is contained in:
PaddleStroke
2024-07-25 01:44:36 +02:00
committed by GitHub
parent 6a5207f7a8
commit 2dc886d748
2 changed files with 52 additions and 0 deletions

View File

@@ -38,6 +38,8 @@
#include <Inventor/sensors/SoSensor.h>
#endif
#include <chrono>
#include <App/Link.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
@@ -96,6 +98,7 @@ ViewProviderAssembly::ViewProviderAssembly()
, moveInCommand(true)
, jointVisibilityBackup(false)
, ctrlPressed(false)
, lastClickTime(0)
, docsToMove({})
{}
@@ -466,6 +469,19 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button,
// Left Mouse button ****************************************************
if (Button == 1) {
if (pressed && !getDraggerVisibility()) {
// Check for double-click
auto now = std::chrono::steady_clock::now();
long nowMillis =
std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch())
.count();
if (nowMillis - lastClickTime < 500) {
// Double-click detected
doubleClickedIn3dView();
return true;
}
// First click detected
lastClickTime = nowMillis;
canStartDragging = true;
}
else { // Button 1 released
@@ -483,6 +499,36 @@ bool ViewProviderAssembly::mouseButtonPressed(int Button,
return false;
}
void ViewProviderAssembly::doubleClickedIn3dView()
{
// Double clicking on a joint should start editing it.
auto sel = Gui::Selection().getSelectionEx("", App::DocumentObject::getClassTypeId());
if (sel.size() != 1) {
return; // Handle double click only if only one obj selected.
}
App::DocumentObject* obj = sel[0].getObject();
if (!obj) {
return;
}
auto* prop = dynamic_cast<App::PropertyBool*>(obj->getPropertyByName("EnableLengthMin"));
if (!prop) {
return;
}
std::string obj_name = obj->getNameInDocument();
std::string doc_name = obj->getDocument()->getName();
std::string cmd = "import JointObject\n"
"obj = App.getDocument('"
+ doc_name + "').getObject('" + obj_name
+ "')\n"
"Gui.Control.showDialog(JointObject.TaskAssemblyCreateJoint(0, obj))";
Gui::Command::runCommand(Gui::Command::App, cmd.c_str());
}
bool ViewProviderAssembly::canDragObjectIn3d(App::DocumentObject* obj) const
{
if (!obj) {

View File

@@ -103,6 +103,9 @@ public:
bool pressed,
const SbVec2s& cursorPos,
const Gui::View3DInventorViewer* viewer) override;
// Function to handle double click event
void doubleClickedIn3dView();
/// Finds what drag mode should be used based on the user selection.
DragMode findDragMode();
@@ -172,6 +175,9 @@ public:
bool moveInCommand;
bool jointVisibilityBackup;
bool ctrlPressed;
long lastClickTime; // Store last click time as milliseconds
int numberOfSel;
Base::Vector3d prevPosition;
Base::Vector3d initialPosition;