I want to create a panning tool

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
hrhassan
Posts: 75
Joined: Mon May 25, 2020 3:25 am

I want to create a panning tool

Post by hrhassan »

I want to make a panning tool in the command bar that when selected, will allow the left mouse button be used for panning, so I want it to activate a different navigation style. However, this is only when this command toggle is selected. Once deselected, you can no longer pan using the left mouse button.

WHAT I HAVE TRIED:
  • I found CADNavigationStyle.cpp in the Source code and tried modifying the button arrangement.
  • Designated a toggle in the Command.cpp and Workspace.cpp
  • Created a new Navigation style file that I would like activated when the toggle is selected
Code I tried to create in CommandView.cpp with the init command from SoFCDB.cpp:

Code: Select all

DEF_STD_CMD_AC(StdPanTool)

StdPanTool::StdPanTool()
    : Command("Std_PanTool")
{
    sGroup = QT_TR_NOOP("View");
    sMenuText = QT_TR_NOOP("Pan");
    sToolTipText = QT_TR_NOOP("Panning tool");
    sWhatsThis = "Std_PanTool";
    sStatusTip = QT_TR_NOOP("Pan across canvas");
    eType = 0;
}

Action* StdPanTool::createAction(void)
{
    Action* pcAction = Command::createAction();
    pcAction->setCheckable(true);
    pcAction->setChecked(true);

    return pcAction;
}

void StdPanTool::activated(int iMsg)
{
PanNavigationStyle::init();


bool StdPanTool::isActive()
{
    static bool checked = false;
    if (!checked) {
        Action* act = this->getAction();
        if (act) {
            act->setChecked(getMainWindow()->statusBar()->isVisible());
            checked = true;
        }
    }
    return true;
}
This code gave me the toggle feature, but did not activate nor deactivate the navigation style.

What I would like to know is how I can activate a certain navigation style when the command toggle is selected.

I am compiling with Visual Studio 2019 and LibPack 12.1.4

Thank you.
Last edited by hrhassan on Wed Jun 10, 2020 1:04 am, edited 2 times in total.
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: I want to create a panning tool

Post by chrisb »

Moved from Install/Compile.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply