]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_WidgetSketchCreator.cpp
Salome HOME
ffccda73aacacb7621752184a65cc454b59b393c
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchCreator.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetSketchCreator.cpp
4 // Created:     08 June 2015
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "PartSet_WidgetSketchCreator.h"
8 #include "PartSet_Module.h"
9
10 #include <XGUI_ModuleConnector.h>
11 #include <XGUI_Workshop.h>
12 #include <XGUI_Displayer.h>
13 #include <XGUI_SelectionMgr.h>
14
15 #include <GeomAPI_Face.h>
16
17 #include <ModuleBase_Tools.h>
18 #include <ModuleBase_Operation.h>
19 #include <ModuleBase_IPropertyPanel.h>
20 #include <Config_WidgetAPI.h>
21
22 #include <QLabel>
23 #include <QLineEdit>
24 #include <QFormLayout>
25
26 PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, 
27                                                          PartSet_Module* theModule,
28                                                          const Config_WidgetAPI* theData,
29                                                          const std::string& theParentId)
30 : ModuleBase_ModelWidget(theParent, theData, theParentId), myModule(theModule)
31 {
32   QFormLayout* aLayout = new QFormLayout(this);
33   ModuleBase_Tools::adjustMargins(aLayout);
34
35   QString aLabelText = QString::fromStdString(theData->widgetLabel());
36   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
37   myLabel = new QLabel(aLabelText, this);
38   if (!aLabelIcon.isEmpty())
39     myLabel->setPixmap(QPixmap(aLabelIcon));
40
41
42   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
43   myTextLine = new QLineEdit(this);
44   myTextLine->setReadOnly(true);
45   myTextLine->setToolTip(aToolTip);
46   myTextLine->installEventFilter(this);
47
48   aLayout->addRow(myLabel, myTextLine);
49 }
50
51 PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
52 {
53 }
54
55 QList<QWidget*> PartSet_WidgetSketchCreator::getControls() const
56 {
57   QList<QWidget*> aControls;
58   aControls.append(myTextLine);
59   return aControls;
60 }
61
62 bool PartSet_WidgetSketchCreator::restoreValue()
63 {
64   return true;
65 }
66
67 bool PartSet_WidgetSketchCreator::storeValueCustom() const
68 {
69   return true;
70 }
71
72 void PartSet_WidgetSketchCreator::activateCustom()
73 {
74   connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
75
76
77   //XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
78   //XGUI_Workshop* aWorkshop = aConnector->workshop();
79   //XGUI_Displayer* aDisp = aWorkshop->displayer();
80
81   //QIntList aModes;
82   //aModes << TopAbs_FACE;
83   //aDisp->activateObjects(aModes);
84   //  
85   //connect(aWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
86   //activateFilters(myModule->workshop(), true);
87 }
88
89 void PartSet_WidgetSketchCreator::onStarted()
90 {
91   disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
92
93   CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
94   FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
95
96   ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
97   anOperation->setFeature(aSketch);
98   myModule->sendOperation(anOperation);
99 }
100
101 void PartSet_WidgetSketchCreator::storeAttributeValue()
102 {
103 }
104
105 void PartSet_WidgetSketchCreator::restoreAttributeValue(const bool theValid)
106 {
107 }
108
109 bool PartSet_WidgetSketchCreator::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
110 {
111   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face());
112   aFace->setImpl(new TopoDS_Shape(thePrs.shape()));
113   if (aFace->isPlanar())
114     return true;
115   //CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
116   //FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
117
118   //ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
119   //anOperation->setFeature(aSketch);
120   //myModule->sendOperation(anOperation);
121   return false;
122 }
123
124 bool PartSet_WidgetSketchCreator::setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition)
125 {
126   return true;
127 }