Files
create/src/Gui/CommandFeat.cpp
Zheng, Lei 2a6bd5e464 Implementation of Link
This patch includes the actual implementation of Link, which is
implemented as an extension named LinkBaseExtension in App namespace,
and a full view provider ViewProviderLink in Gui. The reason of not
using ViewProviderExtension is because it need full control when
display, not just extending existing functionalities.

Please see [here](https://git.io/fjPue) for more details of the
implementation.

This patch also includes a set of link manipulation commands, and a
task panel for overriding geometry element colors.
2019-08-17 15:08:33 +02:00

125 lines
4.7 KiB
C++

/***************************************************************************
* Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#include <App/DocumentObject.h>
#include "Application.h"
#include "Command.h"
#include "Document.h"
#include "Selection.h"
#include "ViewProvider.h"
#include "ViewProviderDocumentObject.h"
#include "ViewProviderLink.h"
using namespace Gui;
//===========================================================================
// Std_Recompute
//===========================================================================
DEF_STD_CMD(StdCmdFeatRecompute);
StdCmdFeatRecompute::StdCmdFeatRecompute()
:Command("Std_Recompute")
{
// setting the
sGroup = QT_TR_NOOP("File");
sMenuText = QT_TR_NOOP("&Recompute");
sToolTipText = QT_TR_NOOP("Recompute feature or document");
sWhatsThis = "Std_Recompute";
sStatusTip = QT_TR_NOOP("Recompute feature or document");
sPixmap = "view-refresh";
sAccel = "Ctrl+R";
}
void StdCmdFeatRecompute::activated(int iMsg)
{
Q_UNUSED(iMsg);
}
//===========================================================================
// Std_RandomColor
//===========================================================================
DEF_STD_CMD_A(StdCmdRandomColor);
StdCmdRandomColor::StdCmdRandomColor()
:Command("Std_RandomColor")
{
sGroup = QT_TR_NOOP("File");
sMenuText = QT_TR_NOOP("Random color");
sToolTipText = QT_TR_NOOP("Random color");
sWhatsThis = "Std_RandomColor";
sStatusTip = QT_TR_NOOP("Random color");
}
void StdCmdRandomColor::activated(int iMsg)
{
Q_UNUSED(iMsg);
// get the complete selection
std::vector<SelectionSingleton::SelObj> sel = Selection().getCompleteSelection();
for (std::vector<SelectionSingleton::SelObj>::iterator it = sel.begin(); it != sel.end(); ++it) {
float fMax = (float)RAND_MAX;
float fRed = (float)rand()/fMax;
float fGrn = (float)rand()/fMax;
float fBlu = (float)rand()/fMax;
ViewProvider* view = Application::Instance->getDocument(it->pDoc)->getViewProvider(it->pObject);
auto vpLink = dynamic_cast<ViewProviderLink*>(view);
if(vpLink) {
if(!vpLink->OverrideMaterial.getValue())
FCMD_VOBJ_CMD2("OverrideMaterial = True",it->pObject);
FCMD_VOBJ_CMD2("ShapeMaterial.DiffuseColor=(%.2f,%.2f,%.2f)", it->pObject, fRed, fGrn, fBlu);
continue;
}
auto color = dynamic_cast<App::PropertyColor*>(view->getPropertyByName("ShapeColor"));
if (color) {
// get the view provider of the selected object and set the shape color
FCMD_VOBJ_CMD2("ShapeColor=(%.2f,%.2f,%.2f)" , it->pObject, fRed, fGrn, fBlu);
}
}
}
bool StdCmdRandomColor::isActive(void)
{
return (Gui::Selection().size() != 0);
}
namespace Gui {
void CreateFeatCommands(void)
{
CommandManager &rcCmdMgr = Application::Instance->commandManager();
rcCmdMgr.addCommand(new StdCmdFeatRecompute());
rcCmdMgr.addCommand(new StdCmdRandomColor());
}
} // namespace Gui