remove unneeded orig files

This commit is contained in:
Stefan Tröger 2016-04-12 19:10:19 +02:00
parent 4119bb7adc
commit 483e64f368
37 changed files with 0 additions and 20826 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,229 +0,0 @@
if(WIN32)
add_definitions(-DFCApp)
add_definitions(-DBOOST_DYN_LINK)
endif(WIN32)
# This causes some problems with the resource files to be found, especially with the StartPage
IF(RESOURCEDIR)
add_definitions(-DRESOURCEDIR="${RESOURCEDIR}")
ENDIF(RESOURCEDIR)
IF(DOCDIR)
add_definitions(-DDOCDIR="${DOCDIR}")
ENDIF(DOCDIR)
include_directories(
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${XercesC_INCLUDE_DIRS}
${QT_INCLUDE_DIR}
${ZLIB_INCLUDE_DIR}
)
set(FreeCADApp_LIBS
FreeCADBase
${Boost_LIBRARIES}
${QT_QTCORE_LIBRARY}
${QT_QTXML_LIBRARY}
)
generate_from_xml(DocumentPy)
generate_from_xml(DocumentObjectPy)
generate_from_xml(DocumentObjectGroupPy)
generate_from_xml(GeoFeaturePy)
generate_from_xml(GeoFeatureGroupPy)
generate_from_xml(PartPy)
generate_from_xml(ComplexGeoDataPy)
generate_from_xml(PropertyContainerPy)
generate_from_xml(MaterialPy)
generate_from_py(FreeCADInit InitScript.h)
generate_from_py(FreeCADTest TestScript.h)
SET(FreeCADApp_XML_SRCS
DocumentObjectGroupPy.xml
DocumentObjectPy.xml
GeoFeaturePy.xml
GeoFeatureGroupPy.xml
PartPy.xml
DocumentPy.xml
PropertyContainerPy.xml
ComplexGeoDataPy.xml
MaterialPy.xml
)
SOURCE_GROUP("XML" FILES ${FreeCADApp_XML_SRCS})
# The document stuff
SET(Document_CPP_SRCS
Annotation.cpp
Document.cpp
DocumentObject.cpp
DocumentObjectFileIncluded.cpp
DocumentObjectGroup.cpp
DocumentObjectGroupPyImp.cpp
PartPyImp.cpp
GeoFeaturePyImp.cpp
DocumentObjectPyImp.cpp
DocumentObserver.cpp
DocumentObserverPython.cpp
DocumentPyImp.cpp
Expression.cpp
FeaturePython.cpp
FeatureTest.cpp
GeoFeature.cpp
GeoFeatureGroupPyImp.cpp
GeoFeatureGroup.cpp
Part.cpp
Origin.cpp
Path.cpp
InventorObject.cpp
MeasureDistance.cpp
Placement.cpp
<<<<<<< ae7effa304095ee3d286ea7bb545636960e262d5
Plane.cpp
Range.cpp
Line.cpp
=======
OriginFeature.cpp
>>>>>>> App/Origin: big refactoring
Transactions.cpp
VRMLObject.cpp
MaterialObject.cpp
MergeDocuments.cpp
)
SET(Document_HPP_SRCS
Annotation.h
Document.h
DocumentObject.h
DocumentObjectFileIncluded.h
DocumentObjectGroup.h
DocumentObserver.h
DocumentObserverPython.h
Expression.h
ExpressionVisitors.h
FeatureCustom.h
FeaturePython.h
FeaturePythonPyImp.h
FeaturePythonPyImp.inl
FeatureTest.h
GeoFeature.h
GeoFeatureGroup.h
Part.h
Origin.h
Path.h
InventorObject.h
MeasureDistance.h
Placement.h
<<<<<<< ae7effa304095ee3d286ea7bb545636960e262d5
Plane.h
Range.h
Line.h
=======
OriginFeature.h
>>>>>>> App/Origin: big refactoring
Transactions.h
VRMLObject.h
MaterialObject.h
MergeDocuments.h
)
SET(Document_SRCS
${Document_CPP_SRCS}
${Document_HPP_SRCS}
)
SOURCE_GROUP("Document" FILES ${Document_SRCS})
# The property stuff
SET(Properties_CPP_SRCS
DynamicProperty.cpp
ObjectIdentifier.cpp
Property.cpp
PropertyContainer.cpp
PropertyContainerPyImp.cpp
PropertyFile.cpp
PropertyGeo.cpp
PropertyLinks.cpp
PropertyPythonObject.cpp
PropertyStandard.cpp
PropertyUnits.cpp
PropertyExpressionEngine.cpp
)
SET(Properties_HPP_SRCS
DynamicProperty.h
ObjectIdentifier.h
Property.h
PropertyContainer.h
PropertyFile.h
PropertyGeo.h
PropertyLinks.h
PropertyPythonObject.h
PropertyStandard.h
PropertyUnits.h
PropertyExpressionEngine.h
)
SET(Properties_SRCS
${Properties_CPP_SRCS}
${Properties_HPP_SRCS}
)
SOURCE_GROUP("Properties" FILES ${Properties_SRCS})
SET(FreeCADApp_CPP_SRCS
${Document_CPP_SRCS}
${Properties_CPP_SRCS}
Application.cpp
ApplicationPy.cpp
Branding.cpp
ColorModel.cpp
ComplexGeoData.cpp
ComplexGeoDataPyImp.cpp
Enumeration.cpp
Material.cpp
MaterialPyImp.cpp
)
SET(FreeCADApp_HPP_SRCS
${Document_HPP_SRCS}
${Properties_HPP_SRCS}
Application.h
Branding.h
ColorModel.h
ComplexGeoData.h
Enumeration.h
Material.h
)
SET(FreeCADApp_SRCS
${FreeCADApp_CPP_SRCS}
${FreeCADApp_HPP_SRCS}
${FreeCADApp_XML_SRCS}
FreeCADInit.py
FreeCADTest.py
PreCompiled.cpp
PreCompiled.h
)
if(MSVC)
add_definitions(-D_PreComp_)
ADD_MSVC_PRECOMPILED_HEADER(FreeCADApp PreCompiled.h PreCompiled.cpp FreeCADApp_CPP_SRCS)
endif(MSVC)
add_library(FreeCADApp SHARED ${FreeCADApp_SRCS})
target_link_libraries(FreeCADApp ${FreeCADApp_LIBS})
SET_BIN_DIR(FreeCADApp FreeCADApp)
if(WIN32)
INSTALL(TARGETS FreeCADApp
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
else(WIN32)
INSTALL(TARGETS FreeCADApp
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif(WIN32)

View File

@ -1,375 +0,0 @@
/***************************************************************************
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
* *
* 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 *
* *
***************************************************************************/
#ifndef APP_DOCUMENT_H
#define APP_DOCUMENT_H
#include <CXX/Objects.hxx>
#include <Base/Observer.h>
#include <Base/Persistence.h>
#include <Base/Type.h>
#include "PropertyContainer.h"
#include "PropertyStandard.h"
#include "PropertyLinks.h"
#include <map>
#include <vector>
#include <stack>
#include <boost/signals.hpp>
#include <boost/graph/adjacency_list.hpp>
namespace Base {
class Writer;
}
namespace App
{
class DocumentObject;
class DocumentObjectExecReturn;
class Document;
class DocumentPy; // the python document class
class Application;
class Transaction;
}
namespace App
{
/// The document class
class AppExport Document : public App::PropertyContainer
{
PROPERTY_HEADER(App::Document);
public:
/** @name Properties */
//@{
/// holds the long name of the document (utf-8 coded)
PropertyString Label;
/// full qualified (with path) file name (utf-8 coded)
PropertyString FileName;
/// creators name (utf-8)
PropertyString CreatedBy;
PropertyString CreationDate;
/// user last modified the document
PropertyString LastModifiedBy;
PropertyString LastModifiedDate;
/// company name UTF8(optional)
PropertyString Company;
/// long comment or description (UTF8 with line breaks)
PropertyString Comment;
/// Id e.g. Part number
PropertyString Id;
/// unique identifier of the document
PropertyUUID Uid;
/** License string
* Holds the short license string for the Item, e.g. CC-BY
* for the Creative Commons license suit.
*/
App::PropertyString License;
/// License descripton/contract URL
App::PropertyString LicenseURL;
/// Meta descriptons
App::PropertyMap Meta;
/// Material descriptons, used and defined in the Material module.
App::PropertyMap Material;
/// read-only name of the temp dir created wen the document is opened
PropertyString TransientDir;
/// Tip object of the document (if any)
PropertyLink Tip;
/// Tip object of the document (if any)
PropertyString TipName;
//@}
/** @name Signals of the document */
//@{
/// signal on new Object
boost::signal<void (const App::DocumentObject&)> signalNewObject;
//boost::signal<void (const App::DocumentObject&)> m_sig;
/// signal on deleted Object
boost::signal<void (const App::DocumentObject&)> signalDeletedObject;
/// signal on changed Object
boost::signal<void (const App::DocumentObject&, const App::Property&)> signalChangedObject;
/// signal on relabeled Object
boost::signal<void (const App::DocumentObject&)> signalRelabelObject;
/// signal on activated Object
boost::signal<void (const App::DocumentObject&)> signalActivatedObject;
/// signal on undo
boost::signal<void (const App::Document&)> signalUndo;
/// signal on redo
boost::signal<void (const App::Document&)> signalRedo;
/** signal on load/save document
* this signal is given when the document gets streamed.
* you can use this hook to write additional information in
* the file (like the Gui::Document it does).
*/
boost::signal<void (Base::Writer &)> signalSaveDocument;
boost::signal<void (Base::XMLReader&)> signalRestoreDocument;
boost::signal<void (const std::vector<App::DocumentObject*>&,
Base::Writer &)> signalExportObjects;
boost::signal<void (const std::vector<App::DocumentObject*>&,
Base::Writer &)> signalExportViewObjects;
boost::signal<void (const std::vector<App::DocumentObject*>&,
Base::XMLReader&)> signalImportObjects;
boost::signal<void (const std::vector<App::DocumentObject*>&, Base::Reader&,
const std::map<std::string, std::string>&)> signalImportViewObjects;
boost::signal<void (const App::Document&)> signalRecomputed;
//@}
/** @name File handling of the document */
//@{
/// Save the Document under a new Name
//void saveAs (const char* Name);
/// Save the document to the file in Property Path
bool save (void);
bool saveAs(const char* file);
bool saveCopy(const char* file);
/// Restore the document from the file in Property Path
void restore (void);
void exportObjects(const std::vector<App::DocumentObject*>&, std::ostream&);
void exportGraphviz(std::ostream&) const;
std::vector<App::DocumentObject*> importObjects(Base::XMLReader& reader);
/// Opens the document from its file name
//void open (void);
/// Is the document already saved to a file
bool isSaved() const;
/// Get the document name
const char* getName() const;
//@}
virtual void Save (Base::Writer &writer) const;
virtual void Restore(Base::XMLReader &reader);
/// returns the complet document mermory consumption, including all managed DocObjects and Undo Redo.
unsigned int getMemSize (void) const;
/** @name Object handling */
//@{
/** Add a feature of sType with sName (ASCII) to this document and set it active.
<<<<<<< aed54b532a8900cea389cf5b8a9e941402f9728f
* Unicode names are set through the Label property.
*/
DocumentObject *addObject(const char* sType, const char* pObjectName=0);
=======
* Unicode names are set through the Label propery.
* @param sType the type of created object
* @param pObjectName if nonNULL use that name otherwise generate a new uniq name based on the \a sType
* @param isNew if false don't call the \c DocumentObject::setupObject() callback (default is true)
*/
DocumentObject *addObject(const char* sType, const char* pObjectName=0, bool isNew=true);
>>>>>>> App: add two callback to DocumentObject to perform initialization/uninitialization inside an object
/// Remove a feature out of the document
void remObject(const char* sName);
/** Add an existing feature with sName (ASCII) to this document and set it active.
* Unicode names are set through the Label property.
* This is an overloaded function of the function above and can be used to create
* a feature outside and add it to the document afterwards.
* \note The passed feature must not yet be added to a document, otherwise an exception
* is raisedd.
*/
void addObject(DocumentObject*, const char* pObjectName=0);
/** Copy an object from another document to this document
* If \a recursive is true then all objects this object depends on
* are copied as well. By default \a recursive is false.
* Returns the copy of the object or 0 if the creation failed.
*/
DocumentObject* copyObject(DocumentObject* obj, bool recursive=false);
/** Move an object from another document to this document
* If \a recursive is true then all objects this object depends on
* are moved as well. By default \a recursive is false.
* Returns the moved object itself or 0 if the object is already part of this
* document..
*/
DocumentObject* moveObject(DocumentObject* obj, bool recursive=false);
/// Returns the active Object of this document
DocumentObject *getActiveObject(void) const;
/// Returns a Object of this document
DocumentObject *getObject(const char *Name) const;
/// Returns true if the DocumentObject is contained in this document
const bool isIn(const DocumentObject *pFeat) const;
/// Returns a Name of an Object or 0
const char *getObjectName(DocumentObject *pFeat) const;
/// Returns a Name of an Object or 0
std::string getUniqueObjectName(const char *Name) const;
/// Returns a name of the form prefix_number. d specifies the number of digits.
std::string getStandardObjectName(const char *Name, int d) const;
/// Returns a list of all Objects
std::vector<DocumentObject*> getObjects() const;
std::vector<DocumentObject*> getObjectsOfType(const Base::Type& typeId) const;
std::vector<DocumentObject*> findObjects(const Base::Type& typeId, const char* objname) const;
/// Returns an array with the correct types already.
template<typename T> inline std::vector<T*> getObjectsOfType() const;
int countObjectsOfType(const Base::Type& typeId) const;
/// get the number of objects in the document
int countObjects(void) const;
//@}
/** @name methods for modification and state handling
*/
//@{
/// Remove all modifications. After this call The document becomes again Valid.
void purgeTouched();
/// check if there is any touched object in this document
bool isTouched(void) const;
/// returns all touched objects
std::vector<App::DocumentObject *> getTouched(void) const;
/// set the document to be closable, this is on by default.
void setClosable(bool);
/// check whether the document can be closed
bool isClosable() const;
/// Recompute all touched features
void recompute();
/// Recompute only one feature
void recomputeFeature(DocumentObject* Feat);
/// get the error log from the recompute run
const std::vector<App::DocumentObjectExecReturn*> &getRecomputeLog(void)const{return _RecomputeLog;}
/// get the text of the error of a spezified object
const char* getErrorDescription(const App::DocumentObject*) const;
//@}
/** @name methods for the UNDO REDO and Transaction handling */
//@{
/// switch the level of Undo/Redo
void setUndoMode(int iMode);
/// switch the level of Undo/Redo
int getUndoMode(void) const;
/// switch the tranaction mode
void setTransactionMode(int iMode);
/// Open a new command Undo/Redo, an UTF-8 name can be specified
void openTransaction(const char* name=0);
// Commit the Command transaction. Do nothing If there is no Command transaction open.
void commitTransaction();
/// Abort the actually running transaction.
void abortTransaction();
/// Check if a transaction is open
bool hasPendingTransaction() const;
/// Set the Undo limit in Byte!
void setUndoLimit(unsigned int UndoMemSize=0);
/// Returns the actual memory consumption of the Undo redo stuff.
unsigned int getUndoMemSize (void) const;
/// Set the Undo limit as stack size
void setMaxUndoStackSize(unsigned int UndoMaxStackSize=20);
/// Set the Undo limit as stack size
unsigned int getMaxUndoStackSize(void)const;
/// Remove all stored Undos and Redos
void clearUndos();
/// Returns the number of stored Undos. If greater than 0 Undo will be effective.
int getAvailableUndos() const;
/// Returns a list of the Undo names
std::vector<std::string> getAvailableUndoNames() const;
/// Will UNDO one step, returns False if no undo was done (Undos == 0).
bool undo();
/// Returns the number of stored Redos. If greater than 0 Redo will be effective.
int getAvailableRedos() const;
/// Returns a list of the Redo names.
std::vector<std::string> getAvailableRedoNames() const;
/// Will REDO one step, returns False if no redo was done (Redos == 0).
bool redo() ;
//@}
/** @name dependency stuff */
//@{
/// write GraphViz file
void writeDependencyGraphViz(std::ostream &out);
/// checks if the graph is directed and has no cycles
bool checkOnCycle(void);
/// get a list of all objects linking to the given object
std::vector<App::DocumentObject*> getInList(const DocumentObject* me) const;
/// Get a complete list of all objects the given objects depend on. The list
/// also contains the given objects!
std::vector<App::DocumentObject*> getDependencyList
(const std::vector<App::DocumentObject*>&) const;
// set Changed
//void setChanged(DocumentObject* change);
//@}
/// Function called to signal that an object identifier has been renamed
void renameObjectIdentifiers(const std::map<App::ObjectIdentifier, App::ObjectIdentifier> & paths);
virtual PyObject *getPyObject(void);
friend class Application;
/// because of transaction handling
friend class DocumentObject;
friend class Transaction;
friend class TransactionObject;
/// Destruction
virtual ~Document();
protected:
/// Construction
Document(void);
void _remObject(DocumentObject* pcObject);
void _addObject(DocumentObject* pcObject, const char* pObjectName);
/// checks if a valid transaction is open
void _checkTransaction(DocumentObject* pcObject);
void breakDependency(DocumentObject* pcObject, bool clear);
std::vector<App::DocumentObject*> readObjects(Base::XMLReader& reader);
void writeObjects(const std::vector<App::DocumentObject*>&, Base::Writer &writer) const;
void onChanged(const Property* prop);
/// callback from the Document objects before property will be changed
void onBeforeChangeProperty(const DocumentObject *Who, const Property *What);
/// callback from the Document objects after property was changed
void onChangedProperty(const DocumentObject *Who, const Property *What);
/// helper which Recompute only this feature
bool _recomputeFeature(DocumentObject* Feat);
void _clearRedos();
/// refresh the internal dependency graph
void _rebuildDependencyList(void);
std::string getTransientDirectoryName(const std::string& uuid, const std::string& filename) const;
private:
// # Data Member of the document +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
std::list<Transaction*> mUndoTransactions;
std::list<Transaction*> mRedoTransactions;
// recompute log
std::vector<App::DocumentObjectExecReturn*> _RecomputeLog;
// pointer to the python class
Py::Object DocumentPythonObject;
struct DocumentP* d;
};
template<typename T>
inline std::vector<T*> Document::getObjectsOfType() const
{
std::vector<T*> type;
std::vector<App::DocumentObject*> obj = this->getObjectsOfType(T::getClassTypeId());
type.reserve(obj.size());
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it)
type.push_back(static_cast<T*>(*it));
return type;
}
} //namespace App
#endif // APP_DOCUMENT_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,98 +0,0 @@
/***************************************************************************
* Copyright (c) 2008 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"
#ifndef _PreComp_
# include <Python.h>
#endif
#include <Base/PyObjectBase.h>
#include <Base/Console.h>
#include <App/PartPy.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/ViewProviderDocumentObject.h>
#include <Mod/PartDesign/App/BodyPy.h>
#include "ViewProviderBody.h"
#include "Utils.h"
//static PyObject * setActiveBody(PyObject *self, PyObject *args)
//{
// PyObject *object=0;
// if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) {
// PartDesign::Body* Item = static_cast<PartDesign::BodyPy*>(object)->getBodyPtr();
// // Should be set!
// assert(Item);
//
// // Set old body inactive if we are activating another body in the same document
// if ((PartDesignGui::ActivePartObject != NULL) &&
// (PartDesignGui::ActivePartObject->getDocument() == Item->getDocument()))
// PartDesignGui::ActivePartObject->IsActive.setValue(false);
// PartDesignGui::ActivePartObject = Item;
// PartDesignGui::ActiveAppDoc = Item->getDocument();
// PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc);
// PartDesignGui::ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*> (PartDesignGui::ActiveGuiDoc->getViewProvider(Item));
// PartDesignGui::ActiveVp->show();
// Item->IsActive.setValue(true);
// } else {
// // This handles the case of deactivating the workbench
// PartDesignGui::ActivePartObject=0;
// PartDesignGui::ActiveGuiDoc =0;
// PartDesignGui::ActiveAppDoc =0;
// PartDesignGui::ActiveVp =0;
// }
//
// Py_Return;
//}
//
//static PyObject * getActiveBody(PyObject *, PyObject *)
//{
// if (PartDesignGui::ActivePartObject == NULL) {
// return Py::_None();
// }
//
// return PartDesignGui::ActivePartObject->getPyObject();
//}
/* registration table */
struct PyMethodDef Assembly_methods[] = {
//{"setActiveBody" ,setActiveBody ,METH_VARARGS,
// "setActiveBody(BodyObject) -- Set the PartBody object in work."},
//{"getActiveBody" ,getActiveBody ,METH_NOARGS,
// "getActiveBody() -- Get the PartBody object in work."},
<<<<<<< f03c0f9bdef9886ee45a086b02fa7ebaa99b6825:src/Mod/Assembly/App/AppAssemblyPy.cpp
{"setUpPart" ,setUpPart ,METH_VARARGS,
"setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."},
{NULL, NULL} /* end of table marker */
=======
{NULL, NULL} /* end of table marker */
>>>>>>> OriginGroup: add new abstraction layer between the Part and the GeoFeatureGroup:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
};

View File

@ -1,81 +0,0 @@
<<<<<<< d6421cef81c1d7a191d1524d88c63e56e3f6d864
<RCC>
<qresource>
<file>icons/Assembly_ConstraintLock.svg</file>
<file>icons/Assembly_ConstraintDistance.svg</file>
<file>icons/Assembly_ConstraintAngle.svg</file>
<file>icons/Assembly_ConstraintOrientation.svg</file>
<file>icons/Assembly_ConstraintCoincidence.svg</file>
<file>icons/Assembly_ConstraintAlignment.svg</file>
<file>translations/Assembly_af.qm</file>
<file>translations/Assembly_de.qm</file>
<file>translations/Assembly_fi.qm</file>
<file>translations/Assembly_fr.qm</file>
<file>translations/Assembly_hr.qm</file>
<file>translations/Assembly_it.qm</file>
<file>translations/Assembly_nl.qm</file>
<file>translations/Assembly_no.qm</file>
<file>translations/Assembly_ru.qm</file>
<file>translations/Assembly_uk.qm</file>
<file>translations/Assembly_tr.qm</file>
<file>translations/Assembly_sv-SE.qm</file>
<file>translations/Assembly_pl.qm</file>
<file>translations/Assembly_zh-TW.qm</file>
<file>translations/Assembly_pt-BR.qm</file>
<file>translations/Assembly_cs.qm</file>
<file>translations/Assembly_sk.qm</file>
<file>translations/Assembly_es-ES.qm</file>
<file>translations/Assembly_zh-CN.qm</file>
<file>translations/Assembly_ja.qm</file>
<file>translations/Assembly_ro.qm</file>
<file>translations/Assembly_hu.qm</file>
<file>translations/Assembly_pt-PT.qm</file>
<file>translations/Assembly_sr.qm</file>
<file>translations/Assembly_el.qm</file>
<file>translations/Assembly_sl.qm</file>
</qresource>
</RCC>
=======
<RCC>
<qresource>
<file>icons/Assembly_ConstraintBidirectional.svg</file>
<file>icons/Assembly_ConstraintUnidirectional1.svg</file>
<file>icons/Assembly_ConstraintUnidirectional2.svg</file>
<file>icons/Assembly_ConstraintPerpendicular.svg</file>
<file>icons/Assembly_ConstraintParallel.svg</file>
<file>icons/Assembly_ConstraintOpposite.svg</file>
<file>icons/Assembly_ConstraintEqual.svg</file>
<file>icons/Assembly_ConstraintLock.svg</file>
<file>icons/Assembly_ConstraintDistance.svg</file>
<file>icons/Assembly_ConstraintAngle.svg</file>
<file>icons/Assembly_ConstraintOrientation.svg</file>
<file>icons/Assembly_ConstraintCoincidence.svg</file>
<file>icons/Assembly_ConstraintAlignment.svg</file>
<file>icons/Assembly_ConstraintGeneral.svg</file>
<file>translations/Assembly_af.qm</file>
<file>translations/Assembly_de.qm</file>
<file>translations/Assembly_fi.qm</file>
<file>translations/Assembly_fr.qm</file>
<file>translations/Assembly_hr.qm</file>
<file>translations/Assembly_it.qm</file>
<file>translations/Assembly_nl.qm</file>
<file>translations/Assembly_no.qm</file>
<file>translations/Assembly_ru.qm</file>
<file>translations/Assembly_uk.qm</file>
<file>translations/Assembly_tr.qm</file>
<file>translations/Assembly_sv-SE.qm</file>
<file>translations/Assembly_pl.qm</file>
<file>translations/Assembly_zh-TW.qm</file>
<file>translations/Assembly_pt-BR.qm</file>
<file>translations/Assembly_cs.qm</file>
<file>translations/Assembly_sk.qm</file>
<file>translations/Assembly_es-ES.qm</file>
<file>translations/Assembly_zh-CN.qm</file>
<file>translations/Assembly_ja.qm</file>
<file>translations/Assembly_ro.qm</file>
<file>translations/Assembly_hu.qm</file>
<file>translations/Assembly_pt-PT.qm</file>
<file>translations/Assembly_sr.qm</file>
</qresource>
</RCC>
>>>>>>> revidsed assembly constraint gui interaction

View File

@ -1,664 +0,0 @@
/***************************************************************************
* Copyright (c) 2013 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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"
#if defined(__MINGW32__)
# define WNT // avoid conflict with GUID
#endif
#ifndef _PreComp_
# include <Python.h>
# include <climits>
# include <Standard_Version.hxx>
# include <Handle_TDocStd_Document.hxx>
# include <Handle_XCAFApp_Application.hxx>
# include <TDocStd_Document.hxx>
# include <XCAFApp_Application.hxx>
# include <STEPCAFControl_Reader.hxx>
# include <STEPCAFControl_Writer.hxx>
# include <STEPControl_Writer.hxx>
# include <IGESCAFControl_Reader.hxx>
# include <IGESCAFControl_Writer.hxx>
# include <IGESControl_Controller.hxx>
# include <IGESData_GlobalSection.hxx>
# include <IGESData_IGESModel.hxx>
# include <Interface_Static.hxx>
# include <Transfer_TransientProcess.hxx>
# include <XSControl_WorkSession.hxx>
# include <APIHeaderSection_MakeHeader.hxx>
# include <OSD_Exception.hxx>
#endif
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
#include "ImportOCAF.h"
//#include "ImportOCAFAssembly.h"
#include <Base/PyObjectBase.h>
#include <Base/Console.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObjectPy.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/ProgressIndicator.h>
#include <Mod/Part/App/ImportIges.h>
#include <Mod/Part/App/ImportStep.h>
#include <Mod/Part/App/encodeFilename.h>
<<<<<<< e2142800e3730f3726818e80efa9d0c125b57558
namespace Import {
class Module : public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("Import")
{
add_varargs_method("open",&Module::importer,
"open(string) -- Open the file and create a new document."
);
add_varargs_method("insert",&Module::importer,
"insert(string,string) -- Insert the file into the given document."
);
add_varargs_method("openAssembly",&Module::importAssembly,
"openAssembly(string) -- Open the assembly file and create a new document."
);
add_varargs_method("export",&Module::exporter,
"export(list,string) -- Export a list of objects into a single file."
);
initialize("This module is the Import module."); // register with Python
if(TargetObjectPy)
target = static_cast<App::DocumentObjectPy*>(TargetObjectPy)->getDocumentObjectPtr();
}
virtual ~Module() {}
private:
Py::Object importer(const Py::Tuple& args)
{
char* Name;
char* DocName=0;
if (!PyArg_ParseTuple(args.ptr(), "et|s","utf-8",&Name,&DocName))
throw Py::Exception();
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
try {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(Utf8Name.c_str());
App::Document *pcDoc = 0;
if (DocName) {
pcDoc = App::GetApplication().getDocument(DocName);
}
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument("Unnamed");
}
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
if (file.hasExtension("stp") || file.hasExtension("step")) {
try {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read STEP file");
}
Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception) {
Handle_Standard_Failure e = Standard_Failure::Caught();
Base::Console().Error("%s\n", e->GetMessageString());
Base::Console().Message("Try to load STEP file without colors...\n");
Part::ImportStepParts(pcDoc,Utf8Name.c_str());
pcDoc->recompute();
}
}
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("IGES");
try {
IGESControl_Controller::Init();
IGESCAFControl_Reader aReader;
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
aReader.SetReadVisible(hGrp->GetBool("SkipBlankEntities", true)
? Standard_True : Standard_False);
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
throw Py::Exception(PyExc_IOError, "cannot read IGES file");
}
Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception) {
Handle_Standard_Failure e = Standard_Failure::Caught();
Base::Console().Error("%s\n", e->GetMessageString());
Base::Console().Message("Try to load IGES file without colors...\n");
Part::ImportIgesParts(pcDoc,Utf8Name.c_str());
pcDoc->recompute();
}
}
else {
throw Py::Exception(Base::BaseExceptionFreeCADError, "no supported file format");
}
#if 1
Import::ImportOCAF ocaf(hDoc, pcDoc, file.fileNamePure());
ocaf.loadShapes();
#else
Import::ImportXCAF xcaf(hDoc, pcDoc, file.fileNamePure());
xcaf.loadShapes();
#endif
pcDoc->recompute();
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Py::Exception(Base::BaseExceptionFreeCADError, e->GetMessageString());
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
return Py::None();
}
Py::Object exporter(const Py::Tuple& args)
{
PyObject* object;
char* Name;
if (!PyArg_ParseTuple(args.ptr(), "Oet",&object,"utf-8",&Name))
throw Py::Exception();
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
try {
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
Import::ExportOCAF ocaf(hDoc);
Py::Sequence list(object);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* part = static_cast<Part::Feature*>(obj);
std::vector<App::Color> colors;
ocaf.saveShape(part, colors);
}
else {
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());
}
}
else if (PyTuple_Check(item) && PyTuple_Size(item) == 2) {
Py::Tuple tuple(*it);
Py::Object item0 = tuple.getItem(0);
Py::Object item1 = tuple.getItem(1);
if (PyObject_TypeCheck(item0.ptr(), &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item0.ptr())->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* part = static_cast<Part::Feature*>(obj);
App::PropertyColorList colors;
colors.setPyObject(item1.ptr());
ocaf.saveShape(part, colors.getValues());
}
else {
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());
}
}
}
}
Base::FileInfo file(Utf8Name.c_str());
if (file.hasExtension("stp") || file.hasExtension("step")) {
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
STEPCAFControl_Writer writer;
writer.Transfer(hDoc, STEPControl_AsIs);
// edit STEP header
#if OCC_VERSION_HEX >= 0x060500
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
#else
APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());
#endif
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("STEP");
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)Utf8Name.c_str()));
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str()));
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str()));
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::GetApplication().getExecutableName()));
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
IFSelect_ReturnStatus ret = writer.Write(name8bit.c_str());
if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) {
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
throw Py::Exception();
}
}
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
IGESControl_Controller::Init();
IGESCAFControl_Writer writer;
IGESData_GlobalSection header = writer.Model()->GlobalSection();
header.SetAuthorName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.author")));
header.SetCompanyName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.company")));
header.SetSendName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.product")));
writer.Model()->SetGlobalSection(header);
writer.Transfer(hDoc);
Standard_Boolean ret = writer.Write(name8bit.c_str());
if (!ret) {
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
throw Py::Exception();
}
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
throw Py::Exception(Base::BaseExceptionFreeCADError, e->GetMessageString());
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
return Py::None();
}
{"importAssembly" ,importAssembly ,METH_VARARGS,
"importAssembly(FileName,Target) -- Import a Assembly file and creates a Assembly structure."},
};
=======
/* module functions */
/*
>>>>>>> remove import dependency on assembly workbench
static PyObject * importAssembly(PyObject *self, PyObject *args)
{
char* Name;
PyObject* TargetObjectPy=0;
if (!PyArg_ParseTuple(args, "et|O!","utf-8",&Name,&(App::DocumentObjectPy::Type),&TargetObjectPy))
return 0;
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
PY_TRY {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(name8bit);
App::DocumentObject* target = nullptr;
if(TargetObjectPy)
target = static_cast<App::DocumentObjectPy*>(TargetObjectPy)->getDocumentObjectPtr();
App::Document *pcDoc = 0;
pcDoc = App::GetApplication().getActiveDocument();
if (!pcDoc)
pcDoc = App::GetApplication().newDocument("ImportedAssembly");
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
if (file.hasExtension("stp") || file.hasExtension("step")) {
try {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
PyErr_SetString(PyExc_Exception, "cannot read STEP file");
return 0;
}
Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception) {
Handle_Standard_Failure e = Standard_Failure::Caught();
Base::Console().Error("%s\n", e->GetMessageString());
Base::Console().Message("Try to load STEP file without colors...\n");
Part::ImportStepParts(pcDoc,Name);
pcDoc->recompute();
}
}
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
try {
IGESControl_Controller::Init();
Interface_Static::SetIVal("read.surfacecurve.mode",3);
IGESCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
PyErr_SetString(PyExc_Exception, "cannot read IGES file");
return 0;
}
Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception) {
Handle_Standard_Failure e = Standard_Failure::Caught();
Base::Console().Error("%s\n", e->GetMessageString());
Base::Console().Message("Try to load IGES file without colors...\n");
Part::ImportIgesParts(pcDoc,Name);
pcDoc->recompute();
}
}
else {
PyErr_SetString(PyExc_Exception, "no supported file format");
return 0;
}
Import::ImportOCAFAssembly ocaf(hDoc, pcDoc, file.fileNamePure(),target);
ocaf.loadAssembly();
pcDoc->recompute();
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
PY_CATCH
Py_Return;
}*/
static PyObject * importer(PyObject *self, PyObject *args)
{
char* Name;
char* DocName=0;
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
return NULL;
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
PY_TRY {
//Base::Console().Log("Insert in Part with %s",Name);
Base::FileInfo file(Utf8Name.c_str());
App::Document *pcDoc = 0;
if (DocName) {
pcDoc = App::GetApplication().getDocument(DocName);
}
if (!pcDoc) {
pcDoc = App::GetApplication().newDocument("Unnamed");
}
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
if (file.hasExtension("stp") || file.hasExtension("step")) {
try {
STEPCAFControl_Reader aReader;
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read STEP file");
return 0;
}
Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100);
aReader.Reader().WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading STEP file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception) {
Handle_Standard_Failure e = Standard_Failure::Caught();
Base::Console().Error("%s\n", e->GetMessageString());
Base::Console().Message("Try to load STEP file without colors...\n");
Part::ImportStepParts(pcDoc,Utf8Name.c_str());
pcDoc->recompute();
}
}
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("IGES");
try {
IGESControl_Controller::Init();
IGESCAFControl_Reader aReader;
// http://www.opencascade.org/org/forum/thread_20603/?forum=3
aReader.SetReadVisible(hGrp->GetBool("SkipBlankEntities", true)
? Standard_True : Standard_False);
aReader.SetColorMode(true);
aReader.SetNameMode(true);
aReader.SetLayerMode(true);
if (aReader.ReadFile((Standard_CString)(name8bit.c_str())) != IFSelect_RetDone) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "cannot read IGES file");
return 0;
}
Handle_Message_ProgressIndicator pi = new Part::ProgressIndicator(100);
aReader.WS()->MapReader()->SetProgress(pi);
pi->NewScope(100, "Reading IGES file...");
pi->Show();
aReader.Transfer(hDoc);
pi->EndScope();
}
catch (OSD_Exception) {
Handle_Standard_Failure e = Standard_Failure::Caught();
Base::Console().Error("%s\n", e->GetMessageString());
Base::Console().Message("Try to load IGES file without colors...\n");
Part::ImportIgesParts(pcDoc,Utf8Name.c_str());
pcDoc->recompute();
}
}
else {
PyErr_SetString(Base::BaseExceptionFreeCADError, "no supported file format");
return 0;
}
#if 1
Import::ImportOCAF ocaf(hDoc, pcDoc, file.fileNamePure());
ocaf.loadShapes();
#else
Import::ImportXCAF xcaf(hDoc, pcDoc, file.fileNamePure());
xcaf.loadShapes();
#endif
pcDoc->recompute();
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString());
return 0;
}
PY_CATCH
Py_Return;
}
static PyObject * open(PyObject *self, PyObject *args)
{
return importer(self, args);
}
static PyObject * exporter(PyObject *self, PyObject *args)
{
PyObject* object;
char* Name;
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
return NULL;
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
std::string name8bit = Part::encodeFilename(Utf8Name);
PY_TRY {
Handle(XCAFApp_Application) hApp = XCAFApp_Application::GetApplication();
Handle(TDocStd_Document) hDoc;
hApp->NewDocument(TCollection_ExtendedString("MDTV-CAF"), hDoc);
Import::ExportOCAF ocaf(hDoc);
Py::Sequence list(object);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* part = static_cast<Part::Feature*>(obj);
std::vector<App::Color> colors;
ocaf.saveShape(part, colors);
}
else {
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());
}
}
else if (PyTuple_Check(item) && PyTuple_Size(item) == 2) {
Py::Tuple tuple(*it);
Py::Object item0 = tuple.getItem(0);
Py::Object item1 = tuple.getItem(1);
if (PyObject_TypeCheck(item0.ptr(), &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item0.ptr())->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* part = static_cast<Part::Feature*>(obj);
App::PropertyColorList colors;
colors.setPyObject(item1.ptr());
ocaf.saveShape(part, colors.getValues());
}
else {
Base::Console().Message("'%s' is not a shape, export will be ignored.\n", obj->Label.getValue());
}
}
}
}
Base::FileInfo file(Utf8Name.c_str());
if (file.hasExtension("stp") || file.hasExtension("step")) {
//Interface_Static::SetCVal("write.step.schema", "AP214IS");
STEPCAFControl_Writer writer;
writer.Transfer(hDoc, STEPControl_AsIs);
// edit STEP header
#if OCC_VERSION_HEX >= 0x060500
APIHeaderSection_MakeHeader makeHeader(writer.ChangeWriter().Model());
#else
APIHeaderSection_MakeHeader makeHeader(writer.Writer().Model());
#endif
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part")->GetGroup("STEP");
makeHeader.SetName(new TCollection_HAsciiString((const Standard_CString)Utf8Name.c_str()));
makeHeader.SetAuthorValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Author", "Author").c_str()));
makeHeader.SetOrganizationValue (1, new TCollection_HAsciiString(hGrp->GetASCII("Company").c_str()));
makeHeader.SetOriginatingSystem(new TCollection_HAsciiString(App::GetApplication().getExecutableName()));
makeHeader.SetDescriptionValue(1, new TCollection_HAsciiString("FreeCAD Model"));
IFSelect_ReturnStatus ret = writer.Write(name8bit.c_str());
if (ret == IFSelect_RetError || ret == IFSelect_RetFail || ret == IFSelect_RetStop) {
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
return 0;
}
}
else if (file.hasExtension("igs") || file.hasExtension("iges")) {
IGESControl_Controller::Init();
IGESCAFControl_Writer writer;
IGESData_GlobalSection header = writer.Model()->GlobalSection();
header.SetAuthorName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.author")));
header.SetCompanyName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.company")));
header.SetSendName(new TCollection_HAsciiString(Interface_Static::CVal("write.iges.header.product")));
writer.Model()->SetGlobalSection(header);
writer.Transfer(hDoc);
Standard_Boolean ret = writer.Write(name8bit.c_str());
if (!ret) {
PyErr_Format(PyExc_IOError, "Cannot open file '%s'", Utf8Name.c_str());
return 0;
}
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(Base::BaseExceptionFreeCADError, e->GetMessageString());
return 0;
}
PY_CATCH
Py_Return;
}
<<<<<<< e2142800e3730f3726818e80efa9d0c125b57558
PyObject* initModule()
{
return (new Module)->module().ptr();
}
} // namespace Import
=======
/* registration table */
struct PyMethodDef Import_Import_methods[] = {
{"open" ,open ,METH_VARARGS,
"open(string) -- Open the file and create a new document."},
{"insert" ,importer ,METH_VARARGS,
"insert(string,string) -- Insert the file into the given document."},
{"export" ,exporter ,METH_VARARGS,
"export(list,string) -- Export a list of objects into a single file."},
// {"importAssembly" ,importAssembly ,METH_VARARGS,
// "importAssembly(FileName,Target) -- Import a Assembly file and creates a Assembly structure."},
{NULL, NULL} /* end of table marker */
};
>>>>>>> remove import dependency on assembly workbench

View File

@ -1,118 +0,0 @@
/***************************************************************************
* Copyright (c) 2008 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"
#ifndef _PreComp_
# include <Python.h>
#endif
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include "FeaturePad.h"
#include "FeatureSolid.h"
#include "FeaturePocket.h"
#include "FeatureFillet.h"
#include "FeatureSketchBased.h"
#include "FeatureRevolution.h"
#include "FeatureGroove.h"
#include "Body.h"
#include "FeatureDressUp.h"
#include "FeatureChamfer.h"
#include "FeatureDraft.h"
<<<<<<< c3c1399b7e8f8ceea8f3c1288ebfe0b6575f4d90
#include "FeatureSubtractive.h"
#include "FeatureAdditive.h"
=======
#include "FeatureFace.h"
>>>>>>> allow non-sketch based additive and subtractive features
#include "FeatureTransformed.h"
#include "FeatureMirrored.h"
#include "FeatureLinearPattern.h"
#include "FeaturePolarPattern.h"
#include "FeatureScaled.h"
#include "FeatureMultiTransform.h"
#include "FeatureHole.h"
#include "DatumPlane.h"
#include "DatumLine.h"
#include "DatumPoint.h"
#include "FeatureBoolean.h"
extern struct PyMethodDef PartDesign_methods[];
PyDoc_STRVAR(module_PartDesign_doc,
"This module is the PartDesign module.");
/* Python entry */
extern "C" {
void PartDesignExport init_PartDesign()
{
// load dependent module
try {
Base::Interpreter().runString("import Part");
Base::Interpreter().runString("import Sketcher");
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
}
Py_InitModule3("_PartDesign", PartDesign_methods, module_PartDesign_doc); /* mod name, table ptr */
Base::Console().Log("Loading PartDesign module... done\n");
// NOTE: To finish the initialization of our own type objects we must
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
// This function is responsible for adding inherited slots from a type's base class.
PartDesign::Feature ::init();
PartDesign::Solid ::init();
PartDesign::DressUp ::init();
PartDesign::FeatureAddSub ::init();
PartDesign::SketchBased ::init();
PartDesign::Transformed ::init();
PartDesign::Mirrored ::init();
PartDesign::LinearPattern ::init();
PartDesign::PolarPattern ::init();
PartDesign::Scaled ::init();
PartDesign::MultiTransform ::init();
PartDesign::Hole ::init();
PartDesign::Body ::init();
PartDesign::Pad ::init();
PartDesign::Pocket ::init();
PartDesign::Fillet ::init();
PartDesign::Revolution ::init();
PartDesign::Groove ::init();
PartDesign::Chamfer ::init();
PartDesign::Draft ::init();
PartDesign::Plane ::init();
PartDesign::Line ::init();
PartDesign::Point ::init();
PartDesign::Boolean ::init();
PartDesign::Point::initHints();
PartDesign::Line ::initHints();
PartDesign::Plane::initHints();
}
} // extern "C"

View File

@ -1,153 +0,0 @@
/***************************************************************************
* Copyright (c) 2010 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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"
#ifndef _PreComp_
# include <BRepFilletAPI_MakeChamfer.hxx>
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#endif
<<<<<<< 50287516b47694e57429cc98f6d5596a06a635d6
#include <Base/Console.h>
#include <Base/Reader.h>
=======
#include <Base/Exception.h>
>>>>>>> Some code unification for DressUp features
#include <Mod/Part/App/TopoShape.h>
#include "FeatureChamfer.h"
using namespace PartDesign;
PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp)
const App::PropertyQuantityConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1};
Chamfer::Chamfer()
{
ADD_PROPERTY(Size,(1.0));
Size.setUnit(Base::Unit::Length);
Size.setConstraints(&floatSize);
}
short Chamfer::mustExecute() const
{
if (Placement.isTouched() || Size.isTouched())
return 1;
return DressUp::mustExecute();
}
App::DocumentObjectExecReturn *Chamfer::execute(void)
{
// NOTE: Normally the Base property and the BaseFeature property should point to the same object.
// The only difference is that the Base property also stores the edges that are to be chamfered
Part::TopoShape TopShape;
try {
TopShape = getBaseShape();
} catch (Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
const std::vector<std::string>& SubVals = Base.getSubValuesStartsWith("Edge");
if (SubVals.size() == 0)
return new App::DocumentObjectExecReturn("No edges specified");
double size = Size.getValue();
this->positionByBaseFeature();
// create an untransformed copy of the basefeature shape
Part::TopoShape baseShape(TopShape);
baseShape.setTransform(Base::Matrix4D());
try {
BRepFilletAPI_MakeChamfer mkChamfer(baseShape._Shape);
TopTools_IndexedMapOfShape mapOfEdges;
TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
TopExp::MapShapesAndAncestors(baseShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
TopExp::MapShapes(baseShape._Shape, TopAbs_EDGE, mapOfEdges);
for (std::vector<std::string>::const_iterator it=SubVals.begin(); it != SubVals.end(); ++it) {
TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str()));
const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First());
mkChamfer.Add(size, edge, face);
}
mkChamfer.Build();
if (!mkChamfer.IsDone())
return new App::DocumentObjectExecReturn("Failed to create chamfer");
TopoDS_Shape shape = mkChamfer.Shape();
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null");
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
void Chamfer::Restore(Base::XMLReader &reader)
{
reader.readElement("Properties");
int Cnt = reader.getAttributeAsInteger("Count");
for (int i=0 ;i<Cnt ;i++) {
reader.readElement("Property");
const char* PropName = reader.getAttribute("name");
const char* TypeName = reader.getAttribute("type");
App::Property* prop = getPropertyByName(PropName);
try {
if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) {
prop->Restore(reader);
}
else if (prop && strcmp(TypeName,"App::PropertyFloatConstraint") == 0 &&
strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) {
App::PropertyFloatConstraint p;
p.Restore(reader);
static_cast<App::PropertyQuantityConstraint*>(prop)->setValue(p.getValue());
}
}
catch (const Base::XMLParseException&) {
throw; // re-throw
}
catch (const Base::Exception &e) {
Base::Console().Error("%s\n", e.what());
}
catch (const std::exception &e) {
Base::Console().Error("%s\n", e.what());
}
reader.readEndElement("Property");
}
reader.readEndElement("Properties");
}

View File

@ -1,171 +0,0 @@
/***************************************************************************
* Copyright (c) 2010 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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"
#ifndef _PreComp_
#endif
#include "FeatureDressUp.h"
#include <Base/Exception.h>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopExp.hxx>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS_Edge.hxx>
using namespace PartDesign;
namespace PartDesign {
PROPERTY_SOURCE(PartDesign::DressUp, PartDesign::Feature)
DressUp::DressUp()
{
ADD_PROPERTY(Base,(0));
Placement.StatusBits.set(2, true);
}
short DressUp::mustExecute() const
{
if (Base.getValue() && Base.getValue()->isTouched())
return 1;
return PartDesign::Feature::mustExecute();
}
void DressUp::positionByBaseFeature(void)
{
Part::Feature *base = static_cast<Part::Feature*>(BaseFeature.getValue());
if (base && base->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
this->Placement.setValue(base->Placement.getValue());
}
Part::TopoShape DressUp::getBaseShape()
{
App::DocumentObject* link = BaseFeature.getValue();
if (!link)
link = this->Base.getValue(); // For legacy features
if (!link)
throw Base::Exception("No object linked");
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("Linked object is not a Part object");
Part::Feature* base = static_cast<Part::Feature*>(link);
const Part::TopoShape& shape = base->Shape.getShape();
if (shape._Shape.IsNull())
throw Base::Exception("Cannot draft invalid shape");
return shape;
}
void DressUp::getContiniusEdges(Part::TopoShape TopShape, std::vector< std::string >& SubNames) {
TopTools_IndexedMapOfShape mapOfEdges;
TopTools_IndexedDataMapOfShapeListOfShape mapEdgeFace;
TopExp::MapShapesAndAncestors(TopShape._Shape, TopAbs_EDGE, TopAbs_FACE, mapEdgeFace);
TopExp::MapShapes(TopShape._Shape, TopAbs_EDGE, mapOfEdges);
unsigned int i = 0;
while(i < SubNames.size())
{
std::string aSubName = static_cast<std::string>(SubNames.at(i));
if (aSubName.size() > 4 && aSubName.substr(0,4) == "Edge") {
TopoDS_Edge edge = TopoDS::Edge(TopShape.getSubShape(aSubName.c_str()));
const TopTools_ListOfShape& los = mapEdgeFace.FindFromKey(edge);
if(los.Extent() != 2)
{
SubNames.erase(SubNames.begin()+i);
continue;
}
const TopoDS_Shape& face1 = los.First();
const TopoDS_Shape& face2 = los.Last();
GeomAbs_Shape cont = BRep_Tool::Continuity(TopoDS::Edge(edge),
TopoDS::Face(face1),
TopoDS::Face(face2));
if (cont != GeomAbs_C0) {
SubNames.erase(SubNames.begin()+i);
continue;
}
i++;
}
else if(aSubName.size() > 4 && aSubName.substr(0,4) == "Face") {
TopoDS_Face face = TopoDS::Face(TopShape.getSubShape(aSubName.c_str()));
TopTools_IndexedMapOfShape mapOfFaces;
TopExp::MapShapes(face, TopAbs_EDGE, mapOfFaces);
for(int j = 1; j <= mapOfFaces.Extent(); ++j) {
TopoDS_Edge edge = TopoDS::Edge(mapOfFaces.FindKey(j));
int id = mapOfEdges.FindIndex(edge);
std::stringstream buf;
buf << "Edge";
buf << id;
if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end())
{
SubNames.push_back(buf.str());
}
}
SubNames.erase(SubNames.begin()+i);
}
// empty name or any other sub-element
else {
SubNames.erase(SubNames.begin()+i);
}
}
}
void DressUp::onChanged(const App::Property* prop)
{
// the BaseFeature property should always link to the same feature as the Base
if (prop == &BaseFeature) {
<<<<<<< 3108a1b6d1b9743ebed7c154a07a695bb7207a5d
// if attached to a sketch then mark it as read-only
this->Placement.setStatus(App::Property::ReadOnly, BaseFeature.getValue() != 0);
=======
if (Base.getValue() != BaseFeature.getValue()) {
Base.setValue (BaseFeature.getValue());
}
} else if (prop == &Base) {
// track the vice-versa changes
if (Base.getValue() != BaseFeature.getValue()) {
BaseFeature.setValue (Base.getValue());
}
>>>>>>> PartDesign/FeatureDressUp: make Base and BaseFeature properties track the same feature
}
Feature::onChanged(prop);
}
}

View File

@ -1,155 +0,0 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <BRepAlgo.hxx>
# include <BRepFilletAPI_MakeFillet.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
<<<<<<< 2c7cc8276bd6dd4ccc4aa28daa809a688bd493c5
# include <TopTools_ListOfShape.hxx>
=======
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <BRep_Tool.hxx>
>>>>>>> allow to add faces to fillet and chamfer
#endif
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Reader.h>
#include <Mod/Part/App/TopoShape.h>
#include "FeatureFillet.h"
using namespace PartDesign;
PROPERTY_SOURCE(PartDesign::Fillet, PartDesign::DressUp)
const App::PropertyQuantityConstraint::Constraints floatRadius = {0.0,FLT_MAX,0.1};
Fillet::Fillet()
{
ADD_PROPERTY(Radius,(1.0));
Radius.setUnit(Base::Unit::Length);
Radius.setConstraints(&floatRadius);
}
short Fillet::mustExecute() const
{
if (Placement.isTouched() || Radius.isTouched())
return 1;
return DressUp::mustExecute();
}
App::DocumentObjectExecReturn *Fillet::execute(void)
{
Part::TopoShape TopShape;
try {
TopShape = getBaseShape();
} catch (Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
std::vector<std::string> SubNames = std::vector<std::string>(Base.getSubValues());
getContiniusEdges(TopShape, SubNames);
if (SubNames.size() == 0)
return new App::DocumentObjectExecReturn("Fillet not possible on selected shapes");
double radius = Radius.getValue();
this->positionByBaseFeature();
// create an untransformed copy of the base shape
Part::TopoShape baseShape(TopShape);
baseShape.setTransform(Base::Matrix4D());
try {
BRepFilletAPI_MakeFillet mkFillet(baseShape._Shape);
for (std::vector<std::string>::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) {
TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str()));
mkFillet.Add(radius, edge);
}
mkFillet.Build();
if (!mkFillet.IsDone())
return new App::DocumentObjectExecReturn("Failed to create fillet");
TopoDS_Shape shape = mkFillet.Shape();
if (shape.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null");
TopTools_ListOfShape aLarg;
aLarg.Append(baseShape._Shape);
if (!BRepAlgo::IsValid(aLarg, shape, Standard_False, Standard_False)) {
return new App::DocumentObjectExecReturn("Resulting shape is invalid");
}
this->Shape.setValue(shape);
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
void Fillet::Restore(Base::XMLReader &reader)
{
reader.readElement("Properties");
int Cnt = reader.getAttributeAsInteger("Count");
for (int i=0 ;i<Cnt ;i++) {
reader.readElement("Property");
const char* PropName = reader.getAttribute("name");
const char* TypeName = reader.getAttribute("type");
App::Property* prop = getPropertyByName(PropName);
try {
if (prop && strcmp(prop->getTypeId().getName(), TypeName) == 0) {
prop->Restore(reader);
}
else if (prop && strcmp(TypeName,"App::PropertyFloatConstraint") == 0 &&
strcmp(prop->getTypeId().getName(), "App::PropertyQuantityConstraint") == 0) {
App::PropertyFloatConstraint p;
p.Restore(reader);
static_cast<App::PropertyQuantityConstraint*>(prop)->setValue(p.getValue());
}
}
catch (const Base::XMLParseException&) {
throw; // re-throw
}
catch (const Base::Exception &e) {
Base::Console().Error("%s\n", e.what());
}
catch (const std::exception &e) {
Base::Console().Error("%s\n", e.what());
}
reader.readEndElement("Property");
}
reader.readEndElement("Properties");
}

File diff suppressed because it is too large Load Diff

View File

@ -1,166 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QPixmap>
# include <QDialog>
# include <QListIterator>
#endif
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/MainWindow.h>
#include <App/Document.h>
#include <Base/Tools.h>
#include "ui_FeaturePickDialog.h"
#include "FeaturePickDialog.h"
using namespace PartDesignGui;
const QString FeaturePickDialog::getFeatureStatusString(const featureStatus st)
{
switch (st) {
case validFeature: return tr("Valid");
case invalidShape: return tr("Invalid shape");
case noWire: return tr("No wire in sketch");
case isUsed: return tr("Sketch already used by other feature");
case otherBody: return tr("Sketch belongs to another Body feature");
}
return tr("");
}
FeaturePickDialog::FeaturePickDialog(std::vector<App::DocumentObject*>& objects,
const std::vector<featureStatus>& status)
: QDialog(Gui::getMainWindow()), ui(new Ui_FeaturePickDialog)
{
ui->setupUi(this);
<<<<<<< 90079612b9f3db27654ac1d04ee2262d99842e1b
for (std::vector<App::DocumentObject*>::const_iterator o = objects.begin(); o != objects.end(); ++o)
ui->listWidget->addItem(QString::fromLatin1((*o)->getNameInDocument()));
=======
connect(ui->checkOtherBody, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherBody(bool)));
connect(ui->checkOtherFeature, SIGNAL(toggled(bool)), this, SLOT(onCheckOtherFeature(bool)));
connect(ui->radioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioDependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
ui->checkOtherBody->setChecked(false);
ui->checkOtherBody->setEnabled(false); // TODO: implement
ui->checkOtherFeature->setChecked(false);
ui->checkOtherFeature->setEnabled(false); // TODO: implement
ui->radioIndependent->setChecked(true);
ui->radioIndependent->setEnabled(false);
// These are not implemented yet
ui->radioDependent->setEnabled(false);
ui->radioXRef->setEnabled(false);
std::vector<featureStatus>::const_iterator st = status.begin();
for (std::vector<App::DocumentObject*>::const_iterator o = objects.begin(); o != objects.end(); ++o) {
QListWidgetItem* item = new QListWidgetItem(QString::fromAscii((*o)->getNameInDocument()) +
QString::fromAscii(" (") + getFeatureStatusString(*st) + QString::fromAscii(")"));
ui->listWidget->addItem(item);
st++;
}
statuses = status;
updateList();
>>>>>>> Enhanced Pick dialog for PartDesign feature's sketches
}
FeaturePickDialog::~FeaturePickDialog()
{
}
void FeaturePickDialog::updateList()
{
int index = 0;
for (std::vector<featureStatus>::const_iterator st = statuses.begin(); st != statuses.end(); st++) {
QListWidgetItem* item = ui->listWidget->item(index);
switch (*st) {
case validFeature: item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); break;
case invalidShape: item->setFlags(Qt::NoItemFlags); break;
case noWire: item->setFlags(Qt::NoItemFlags); break;
case isUsed: item->setFlags(ui->checkOtherFeature->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
case otherBody: item->setFlags(ui->checkOtherBody->isChecked() ? Qt::ItemIsSelectable | Qt::ItemIsEnabled : Qt::NoItemFlags); break;
}
index++;
}
}
void FeaturePickDialog::onCheckOtherFeature(bool checked)
{
ui->radioIndependent->setEnabled(checked);
// TODO: Not implemented yet
//ui->radioDependent->setEnabled(checked);
//ui->radioXRef->setEnabled(checked);
updateList();
}
void FeaturePickDialog::onCheckOtherBody(bool checked)
{
ui->radioIndependent->setEnabled(checked);
// TODO: Not implemented yet
//ui->radioDependent->setEnabled(checked);
//ui->radioXRef->setEnabled(checked);
updateList();
}
void FeaturePickDialog::onUpdate(bool)
{
updateList();
}
std::vector<App::DocumentObject*> FeaturePickDialog::getFeatures() {
std::vector<App::DocumentObject*> result;
for (std::vector<QString>::const_iterator s = features.begin(); s != features.end(); ++s)
result.push_back(App::GetApplication().getActiveDocument()->getObject(s->toLatin1().data()));
return result;
}
void FeaturePickDialog::accept()
{
features.clear();
QListIterator<QListWidgetItem*> i(ui->listWidget->selectedItems());
while (i.hasNext()) {
QString t = i.next()->text();
t = t.left(t.indexOf(QString::fromAscii("(")) - 1);
features.push_back(t);
}
QDialog::accept();
}
#include "moc_FeaturePickDialog.cpp"

View File

@ -1,79 +0,0 @@
<RCC>
<qresource>
<file>icons/PartDesign_Chamfer.svg</file>
<file>icons/PartDesign_Fillet.svg</file>
<file>icons/PartDesign_Draft.svg</file>
<file>icons/PartDesign_Thickness.svg</file>
<file>icons/PartDesign_Groove.svg</file>
<file>icons/PartDesign_Pad.svg</file>
<file>icons/PartDesign_Pocket.svg</file>
<file>icons/PartDesign_Revolution.svg</file>
<file>icons/PartDesign_Mirrored.svg</file>
<file>icons/PartDesign_LinearPattern.svg</file>
<file>icons/PartDesign_PolarPattern.svg</file>
<file>icons/PartDesign_Scaled.svg</file>
<file>icons/PartDesign_MultiTransform.svg</file>
<file>icons/PartDesign_Hole.svg</file>
<file>icons/PartDesign_Body.svg</file>
<file>icons/PartDesign_Boolean.svg</file>
<file>icons/PartDesign_Plane.svg</file>
<file>icons/PartDesign_Line.svg</file>
<file>icons/PartDesign_Point.svg</file>
<file>icons/PartDesign_CoordinateSystem.svg</file>
<file>icons/PartDesign_MoveTip.svg</file>
<file>icons/Tree_PartDesign_Pad.svg</file>
<file>icons/Tree_PartDesign_Revolution.svg</file>
<file>icons/PartDesign_InternalExternalGear.svg</file>
<file>icons/PartDesign_InvoluteGear.svg</file>
<<<<<<< a6cae97ea944460d610fe5b54eee2890a927dc00
<file>icons/PartDesignWorkbench.svg</file>
<file>icons/PartDesign_Body_Create_New.svg</file>
=======
<file>icons/PartDesign_Body_Create_New.svg</file>
>>>>>>> add basic part design pipe infrastructure
<file>icons/PartDesign_Body_Tree.svg</file>
<file>icons/PartDesign_Additive_Pipe.svg</file>
<file>icons/PartDesign_Additive_Box.svg</file>
<file>icons/PartDesign_Additive_Cylinder.svg</file>
<file>icons/PartDesign_Additive_Sphere.svg</file>
<file>icons/PartDesign_Additive_Cone.svg</file>
<file>icons/PartDesign_Additive_Torus.svg</file>
<file>icons/PartDesign_Additive_Ellipsoid.svg</file>
<file>icons/PartDesign_Additive_Prism.svg</file>
<file>icons/PartDesign_Additive_Wedge.svg</file>
<file>icons/PartDesign_Subtractive_Box.svg</file>
<file>icons/PartDesign_Subtractive_Cylinder.svg</file>
<file>icons/PartDesign_Subtractive_Sphere.svg</file>
<file>icons/PartDesign_Subtractive_Cone.svg</file>
<file>icons/PartDesign_Subtractive_Torus.svg</file>
<file>icons/PartDesign_Subtractive_Ellipsoid.svg</file>
<file>icons/PartDesign_Subtractive_Prism.svg</file>
<file>icons/PartDesign_Subtractive_Wedge.svg</file>
<file>translations/PartDesign_af.qm</file>
<file>translations/PartDesign_de.qm</file>
<file>translations/PartDesign_fi.qm</file>
<file>translations/PartDesign_fr.qm</file>
<file>translations/PartDesign_hr.qm</file>
<file>translations/PartDesign_it.qm</file>
<file>translations/PartDesign_nl.qm</file>
<file>translations/PartDesign_no.qm</file>
<file>translations/PartDesign_pl.qm</file>
<file>translations/PartDesign_ru.qm</file>
<file>translations/PartDesign_uk.qm</file>
<file>translations/PartDesign_tr.qm</file>
<file>translations/PartDesign_sv-SE.qm</file>
<file>translations/PartDesign_zh-TW.qm</file>
<file>translations/PartDesign_pt-BR.qm</file>
<file>translations/PartDesign_cs.qm</file>
<file>translations/PartDesign_sk.qm</file>
<file>translations/PartDesign_es-ES.qm</file>
<file>translations/PartDesign_zh-CN.qm</file>
<file>translations/PartDesign_ja.qm</file>
<file>translations/PartDesign_ro.qm</file>
<file>translations/PartDesign_hu.qm</file>
<file>translations/PartDesign_pt-PT.qm</file>
<file>translations/PartDesign_sr.qm</file>
<file>translations/PartDesign_el.qm</file>
<file>translations/PartDesign_sl.qm</file>
</qresource>
</RCC>

View File

@ -1,90 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskChamferParameters_H
#define GUI_TASKVIEW_TaskChamferParameters_H
#include "TaskDressUpParameters.h"
#include "ViewProviderChamfer.h"
class Ui_TaskChamferParameters;
namespace PartDesignGui {
class TaskChamferParameters : public TaskDressUpParameters
{
Q_OBJECT
public:
TaskChamferParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0);
~TaskChamferParameters();
virtual void apply();
private Q_SLOTS:
void onLengthChanged(double);
void onRefDeleted(void);
protected:
virtual void clearButtons(const selectionModes notThis);
void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
double getLength(void) const;
private:
Ui_TaskChamferParameters* ui;
};
/// simulation dialog for the TaskView
class TaskDlgChamferParameters : public TaskDlgDressUpParameters
{
Q_OBJECT
public:
TaskDlgChamferParameters(ViewProviderChamfer *DressUpView);
~TaskDlgChamferParameters();
public:
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
<<<<<<< 61d7568d0ff2d3e87f1abb738517f4294c5a6d2e
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
protected:
ViewProviderChamfer *ChamferView;
TaskChamferParameters *parameter;
=======
>>>>>>> Allow selecting and removing fillet and chamfer references in the dialog
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TaskChamferParameters_H

View File

@ -1,332 +0,0 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QMessageBox>
#endif
#include "ui_TaskDraftParameters.h"
#include "TaskDraftParameters.h"
#include "Workbench.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/MainWindow.h>
#include <Mod/PartDesign/App/FeatureDraft.h>
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskDraftParameters */
TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView,QWidget *parent)
: TaskDressUpParameters(DressUpView, parent)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskDraftParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
connect(ui->draftAngle, SIGNAL(valueChanged(double)),
this, SLOT(onAngleChanged(double)));
connect(ui->checkReverse, SIGNAL(toggled(bool)),
this, SLOT(onReversedChanged(bool)));
connect(ui->buttonRefAdd, SIGNAL(toggled(bool)),
this, SLOT(onButtonRefAdd(bool)));
connect(ui->buttonRefRemove, SIGNAL(toggled(bool)),
this, SLOT(onButtonRefRemove(bool)));
connect(ui->buttonPlane, SIGNAL(toggled(bool)),
this, SLOT(onButtonPlane(bool)));
connect(ui->buttonLine, SIGNAL(toggled(bool)),
this, SLOT(onButtonLine(bool)));
this->groupLayout()->addWidget(proxy);
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
double a = pcDraft->Angle.getValue();
ui->draftAngle->setMinimum(0.0);
ui->draftAngle->setMaximum(89.99);
ui->draftAngle->setValue(a);
ui->draftAngle->selectAll();
QMetaObject::invokeMethod(ui->draftAngle, "setFocus", Qt::QueuedConnection);
bool r = pcDraft->Reversed.getValue();
ui->checkReverse->setChecked(r);
std::vector<std::string> strings = pcDraft->Base.getSubValues();
for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); ++i)
{
ui->listWidgetReferences->insertItem(0, QString::fromStdString(*i));
}
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetReferences->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onRefDeleted()));
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
App::DocumentObject* ref = pcDraft->NeutralPlane.getValue();
strings = pcDraft->NeutralPlane.getSubValues();
ui->linePlane->setText(getRefStr(ref, strings));
ref = pcDraft->PullDirection.getValue();
strings = pcDraft->PullDirection.getSubValues();
ui->lineLine->setText(getRefStr(ref, strings));
}
void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (selectionMode == none)
return;
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (referenceSelected(msg)) {
if (selectionMode == refAdd)
ui->listWidgetReferences->insertItem(0, QString::fromStdString(msg.pSubName));
else
removeItemFromListWidget(ui->listWidgetReferences, msg.pSubName);
clearButtons(none);
exitSelectionMode();
} else if (selectionMode == plane) {
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
std::vector<std::string> planes;
App::DocumentObject* selObj;
getReferencedSelection(pcDraft, msg, selObj, planes);
pcDraft->NeutralPlane.setValue(selObj, planes);
ui->linePlane->setText(getRefStr(selObj, planes));
pcDraft->getDocument()->recomputeFeature(pcDraft);
clearButtons(none);
exitSelectionMode();
} else if (selectionMode == line) {
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
std::vector<std::string> edges;
App::DocumentObject* selObj;
getReferencedSelection(pcDraft, msg, selObj, edges);
pcDraft->PullDirection.setValue(selObj, edges);
ui->lineLine->setText(getRefStr(selObj, edges));
pcDraft->getDocument()->recomputeFeature(pcDraft);
clearButtons(none);
exitSelectionMode();
}
}
}
void TaskDraftParameters::clearButtons(const selectionModes notThis)
{
if (notThis != refAdd) ui->buttonRefAdd->setChecked(false);
if (notThis != refRemove) ui->buttonRefRemove->setChecked(false);
if (notThis != line) ui->buttonLine->setChecked(false);
if (notThis != plane) ui->buttonPlane->setChecked(false);
}
void TaskDraftParameters::onButtonPlane(bool checked)
{
if (checked) {
clearButtons(plane);
hideObject();
selectionMode = plane;
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, true, true));
}
}
void TaskDraftParameters::onButtonLine(bool checked)
{
if (checked) {
clearButtons(line);
hideObject();
selectionMode = line;
Gui::Selection().clearSelection();
Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), true, false, true));
}
}
void TaskDraftParameters::onRefDeleted(void)
{
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
App::DocumentObject* base = pcDraft->Base.getValue();
std::vector<std::string> faces = pcDraft->Base.getSubValues();
faces.erase(faces.begin() + ui->listWidgetReferences->currentRow());
pcDraft->Base.setValue(base, faces);
ui->listWidgetReferences->model()->removeRow(ui->listWidgetReferences->currentRow());
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
void TaskDraftParameters::getPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const
{
sub = std::vector<std::string>(1,"");
QStringList parts = ui->linePlane->text().split(QChar::fromAscii(':'));
obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
if (parts.size() > 1)
sub[0] = parts[1].toStdString();
}
void TaskDraftParameters::getLine(App::DocumentObject*& obj, std::vector<std::string>& sub) const
{
sub = std::vector<std::string>(1,"");
QStringList parts = ui->lineLine->text().split(QChar::fromAscii(':'));
obj = DressUpView->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
if (parts.size() > 1)
sub[0] = parts[1].toStdString();
}
void TaskDraftParameters::onAngleChanged(double angle)
{
clearButtons(none);
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
pcDraft->Angle.setValue(angle);
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
const double TaskDraftParameters::getAngle(void) const
{
return ui->draftAngle->value().getValue();
}
void TaskDraftParameters::onReversedChanged(const bool on) {
clearButtons(none);
PartDesign::Draft* pcDraft = static_cast<PartDesign::Draft*>(DressUpView->getObject());
pcDraft->Reversed.setValue(on);
pcDraft->getDocument()->recomputeFeature(pcDraft);
}
const bool TaskDraftParameters::getReversed(void) const
{
return ui->checkReverse->isChecked();
}
TaskDraftParameters::~TaskDraftParameters()
{
Gui::Selection().rmvSelectionGate();
delete ui;
}
void TaskDraftParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DressUpView)
: TaskDlgDressUpParameters(DressUpView)
{
parameter = new TaskDraftParameters(DressUpView);
Content.push_back(parameter);
}
TaskDlgDraftParameters::~TaskDlgDraftParameters()
{
}
//==== calls from the TaskView ===============================================================
//void TaskDlgDraftParameters::open()
//{
// // a transaction is already open at creation time of the draft
// if (!Gui::Command::hasPendingCommand()) {
// QString msg = QObject::tr("Edit draft");
// Gui::Command::openCommand((const char*)msg.toUtf8());
// }
//}
bool TaskDlgDraftParameters::accept()
{
parameter->showObject();
// Force the user to select a neutral plane
std::vector<std::string> strings;
App::DocumentObject* obj;
TaskDraftParameters* draftparameter = static_cast<TaskDraftParameters*>(parameter);
draftparameter->getPlane(obj, strings);
std::string neutralPlane = getPythonStr(obj, strings);
if (neutralPlane.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Missing neutral plane"),
QObject::tr("Please select a plane or an edge plus a pull direction"));
return false;
}
<<<<<<< 7e34fb3b6f610a533bbd50991d4b09cf063cda7b
std::string name = DraftView->getObject()->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),parameter->getReversed());
try {
std::vector<std::string> faces = parameter->getFaces();
std::stringstream str;
str << "App.ActiveDocument." << name.c_str() << ".Base = (App.ActiveDocument."
<< parameter->getBase()->getNameInDocument() << ",[";
for (std::vector<std::string>::const_iterator it = faces.begin(); it != faces.end(); ++it)
str << "\"" << *it << "\",";
str << "])";
Gui::Command::doCommand(Gui::Command::Doc,str.str().c_str());
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
}
=======
std::string name = DressUpView->getObject()->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),draftparameter->getAngle());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed());
>>>>>>> Unify code of Dressup features (part 1: Draft)
if (!neutralPlane.empty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = %s", name.c_str(), neutralPlane.c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.NeutralPlane = None", name.c_str());
draftparameter->getLine(obj, strings);
std::string pullDirection = getPythonStr(obj, strings);
if (!pullDirection.empty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = %s", name.c_str(), pullDirection.c_str());
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.PullDirection = None", name.c_str());
return TaskDlgDressUpParameters::accept();
}
#include "moc_TaskDraftParameters.cpp"

View File

@ -1,96 +0,0 @@
/***************************************************************************
* Copyright (c) 2012 Jan Rheinländer <jrheinlaender@users.sourceforge.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskDraftParameters_H
#define GUI_TASKVIEW_TaskDraftParameters_H
#include "TaskDressUpParameters.h"
#include "ViewProviderDraft.h"
class Ui_TaskDraftParameters;
namespace PartDesignGui {
class TaskDraftParameters : public TaskDressUpParameters
{
Q_OBJECT
public:
TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0);
~TaskDraftParameters();
const double getAngle(void) const;
const bool getReversed(void) const;
const std::vector<std::string> getFaces(void) const;
void getPlane(App::DocumentObject*& obj, std::vector<std::string>& sub) const;
void getLine(App::DocumentObject*& obj, std::vector<std::string>& sub) const;
private Q_SLOTS:
void onAngleChanged(double angle);
void onReversedChanged(bool reversed);
void onButtonPlane(const bool checked);
void onButtonLine(const bool checked);
void onRefDeleted(void);
protected:
virtual void clearButtons(const selectionModes notThis);
void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
private:
Ui_TaskDraftParameters* ui;
};
/// simulation dialog for the TaskView
class TaskDlgDraftParameters : public TaskDlgDressUpParameters
{
Q_OBJECT
public:
TaskDlgDraftParameters(ViewProviderDraft *DraftView);
~TaskDlgDraftParameters();
public:
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
<<<<<<< 7e34fb3b6f610a533bbd50991d4b09cf063cda7b
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
protected:
ViewProviderDraft *DraftView;
TaskDraftParameters *parameter;
=======
>>>>>>> Unify code of Dressup features (part 1: Draft)
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TASKAPPERANCE_H

View File

@ -1,90 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskFilletParameters_H
#define GUI_TASKVIEW_TaskFilletParameters_H
#include "TaskDressUpParameters.h"
#include "ViewProviderFillet.h"
class Ui_TaskFilletParameters;
namespace PartDesignGui {
class TaskFilletParameters : public TaskDressUpParameters
{
Q_OBJECT
public:
TaskFilletParameters(ViewProviderDressUp *DressUpView, QWidget *parent=0);
~TaskFilletParameters();
virtual void apply();
private Q_SLOTS:
void onLengthChanged(double);
void onRefDeleted(void);
protected:
double getLength(void) const;
virtual void clearButtons(const selectionModes notThis);
void changeEvent(QEvent *e);
virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
private:
Ui_TaskFilletParameters* ui;
};
/// simulation dialog for the TaskView
class TaskDlgFilletParameters : public TaskDlgDressUpParameters
{
Q_OBJECT
public:
TaskDlgFilletParameters(ViewProviderFillet *DressUpView);
~TaskDlgFilletParameters();
public:
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
<<<<<<< 61d7568d0ff2d3e87f1abb738517f4294c5a6d2e
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
protected:
ViewProviderFillet *FilletView;
TaskFilletParameters *parameter;
=======
>>>>>>> Allow selecting and removing fillet and chamfer references in the dialog
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TaskFilletParameters_H

View File

@ -1,458 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
#endif
#include "ui_TaskGrooveParameters.h"
#include "TaskGrooveParameters.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/DatumLine.h>
#include <Mod/PartDesign/App/FeatureGroove.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/Body.h>
#include "Workbench.h"
#include "ReferenceSelection.h"
#include "TaskSketchBasedParameters.h"
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskGrooveParameters */
TaskGrooveParameters::TaskGrooveParameters(ViewProviderGroove *GrooveView,QWidget *parent)
: TaskSketchBasedParameters(GrooveView, parent, "PartDesign_Groove",tr("Groove parameters"))
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskGrooveParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
connect(ui->grooveAngle, SIGNAL(valueChanged(double)),
this, SLOT(onAngleChanged(double)));
connect(ui->axis, SIGNAL(activated(int)),
this, SLOT(onAxisChanged(int)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
this, SLOT(onMidplane(bool)));
connect(ui->checkBoxReversed, SIGNAL(toggled(bool)),
this, SLOT(onReversed(bool)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
this->groupLayout()->addWidget(proxy);
// Temporarily prevent unnecessary feature updates
ui->grooveAngle->blockSignals(true);
ui->axis->blockSignals(true);
ui->checkBoxMidplane->blockSignals(true);
ui->checkBoxReversed->blockSignals(true);
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
double l = pcGroove->Angle.getValue();
bool mirrored = pcGroove->Midplane.getValue();
bool reversed = pcGroove->Reversed.getValue();
ui->grooveAngle->setValue(l);
ui->grooveAngle->bind(pcGroove->Angle);
<<<<<<< f0798a82fe8f03db57aca4f634d2123486daaea0
int count=pcGroove->getSketchAxisCount();
for (int i=ui->axis->count()-1; i >= count+2; i--)
ui->axis->removeItem(i);
for (int i=ui->axis->count(); i < count+2; i++)
ui->axis->addItem(QString::fromLatin1("Sketch axis %1").arg(i-2));
int pos=-1;
App::DocumentObject *pcReferenceAxis = pcGroove->ReferenceAxis.getValue();
const std::vector<std::string> &subReferenceAxis = pcGroove->ReferenceAxis.getSubValues();
if (pcReferenceAxis && pcReferenceAxis == pcGroove->Sketch.getValue()) {
assert(subReferenceAxis.size()==1);
if (subReferenceAxis[0] == "V_Axis")
pos = 0;
else if (subReferenceAxis[0] == "H_Axis")
pos = 1;
else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis")
pos = 2 + std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
}
if (pos < 0 || pos >= ui->axis->count()) {
ui->axis->addItem(QString::fromLatin1("Undefined"));
pos = ui->axis->count()-1;
}
ui->axis->setCurrentIndex(pos);
=======
blockUpdate = false;
updateUI();
>>>>>>> Enable edges and datum lines as rotation axis for Groove and Revolution features
ui->checkBoxMidplane->setChecked(mirrored);
ui->checkBoxReversed->setChecked(reversed);
ui->grooveAngle->blockSignals(false);
ui->axis->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
setFocus ();
}
void TaskGrooveParameters::updateUI()
{
if (blockUpdate)
return;
blockUpdate = true;
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
App::DocumentObject* pcReferenceAxis = pcGroove->ReferenceAxis.getValue();
std::vector<std::string> sub = pcGroove->ReferenceAxis.getSubValues();
// Add user-defined sketch axes to the reference selection combo box
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
int maxcount=2;
if (pcSketch)
maxcount += pcSketch->getAxisCount();
for (int i=ui->axis->count()-1; i >= 2; i--)
ui->axis->removeItem(i);
for (int i=ui->axis->count(); i < maxcount; i++)
ui->axis->addItem(QString::fromAscii("Sketch axis %1").arg(i-5));
bool undefined = false;
if (pcReferenceAxis != NULL && !sub.empty()) {
if (sub.front() == "H_Axis")
ui->axis->setCurrentIndex(0);
else if (sub.front() == "V_Axis")
ui->axis->setCurrentIndex(1);
else if (sub.front().size() > 4 && sub.front().substr(0,4) == "Axis") {
int pos = 2 + std::atoi(sub.front().substr(4,4000).c_str());
if (pos <= maxcount)
ui->axis->setCurrentIndex(pos);
else
undefined = true;
} else {
ui->axis->addItem(getRefStr(pcReferenceAxis, sub));
ui->axis->setCurrentIndex(maxcount);
}
} else {
undefined = true;
}
ui->axis->addItem(tr("Select reference..."));
blockUpdate = false;
}
void TaskGrooveParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
exitSelectionMode();
if (!blockUpdate) {
std::vector<std::string> axis;
App::DocumentObject* selObj;
getReferencedSelection(pcGroove, msg, selObj, axis);
pcGroove->ReferenceAxis.setValue(selObj, axis);
recomputeFeature();
updateUI();
}
else {
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
int maxcount=2;
if (pcSketch)
maxcount += pcSketch->getAxisCount();
for (int i=ui->axis->count()-1; i >= maxcount; i--)
ui->axis->removeItem(i);
std::vector<std::string> sub;
App::DocumentObject* selObj;
getReferencedSelection(pcGroove, msg, selObj, sub);
ui->axis->addItem(getRefStr(selObj, sub));
ui->axis->setCurrentIndex(maxcount);
ui->axis->addItem(tr("Select reference..."));
}
}
}
void TaskGrooveParameters::onAngleChanged(double len)
{
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
pcGroove->Angle.setValue(len);
exitSelectionMode();
recomputeFeature();
}
void TaskGrooveParameters::onAxisChanged(int num)
{
if (blockUpdate)
return;
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
if (pcSketch) {
App::DocumentObject *oldRefAxis = pcGroove->ReferenceAxis.getValue();
std::vector<std::string> oldSubRefAxis = pcGroove->ReferenceAxis.getSubValues();
int maxcount = pcSketch->getAxisCount()+2;
if (num == 0) {
pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
exitSelectionMode();
} else if (num == 1) {
pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
exitSelectionMode();
} else if (num >= 2 && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-2);
std::string str = buf.toStdString();
pcGroove->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,str));
exitSelectionMode();
} else if (num == ui->axis->count() - 1) {
// enter reference selection mode
TaskSketchBasedParameters::onSelectReference(true, true, false, true);
} else if (num == maxcount)
exitSelectionMode();
App::DocumentObject *newRefAxis = pcGroove->ReferenceAxis.getValue();
const std::vector<std::string> &newSubRefAxis = pcGroove->ReferenceAxis.getSubValues();
if (oldRefAxis != newRefAxis ||
oldSubRefAxis.size() != newSubRefAxis.size() ||
oldSubRefAxis[0] != newSubRefAxis[0]) {
bool reversed = pcGroove->suggestReversed();
if (reversed != pcGroove->Reversed.getValue()) {
pcGroove->Reversed.setValue(reversed);
ui->checkBoxReversed->blockSignals(true);
ui->checkBoxReversed->setChecked(reversed);
ui->checkBoxReversed->blockSignals(false);
}
}
}
updateUI();
recomputeFeature();
}
void TaskGrooveParameters::onMidplane(bool on)
{
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
pcGroove->Midplane.setValue(on);
recomputeFeature();
}
void TaskGrooveParameters::onReversed(bool on)
{
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
pcGroove->Reversed.setValue(on);
recomputeFeature();
}
double TaskGrooveParameters::getAngle(void) const
{
return ui->grooveAngle->value().getValue();
}
void TaskGrooveParameters::getReferenceAxis(App::DocumentObject*& obj, std::vector<std::string>& sub) const
{
// get the support and Sketch
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
obj = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
sub = std::vector<std::string>(1,"");
int maxcount=2;
if (obj)
maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount();
if (obj) {
int num = ui->axis->currentIndex();
if (num == 0)
sub[0] = "H_Axis";
else if (num == 1)
sub[0] = "V_Axis";
else if (num >= 2 && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-2);
sub[0] = buf.toStdString();
} else if (num == maxcount && ui->axis->count() == maxcount + 2) {
QStringList parts = ui->axis->currentText().split(QChar::fromAscii(':'));
obj = vp->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
if (parts.size() > 1)
sub[0] = parts[1].toStdString();
} else {
obj = NULL;
}
}
else
obj = NULL;
}
bool TaskGrooveParameters::getMidplane(void) const
{
return ui->checkBoxMidplane->isChecked();
}
bool TaskGrooveParameters::getReversed(void) const
{
return ui->checkBoxReversed->isChecked();
}
TaskGrooveParameters::~TaskGrooveParameters()
{
delete ui;
}
void TaskGrooveParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
void TaskGrooveParameters::apply()
{
App::DocumentObject* groove = vp->getObject();
std::string name = groove->getNameInDocument();
// retrieve sketch and its support object
App::DocumentObject* sketch = 0;
App::DocumentObject* support = 0;
if (groove->getTypeId().isDerivedFrom(PartDesign::Groove::getClassTypeId())) {
sketch = static_cast<PartDesign::Groove*>(groove)->Sketch.getValue<Sketcher::SketchObject*>();
if (sketch) {
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
}
}
//Gui::Command::openCommand("Groove changed");
ui->grooveAngle->apply();
std::vector<std::string> sub;
App::DocumentObject* obj;
parameter->getReferenceAxis(obj, sub);
std::string axis = getPythonStr(obj, sub);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.ReferenceAxis = %s",name.c_str(),axis.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(), getMidplane() ? 1 : 0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(), getReversed() ? 1 : 0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (groove->isValid()) {
if (sketch)
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
if (support)
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
}
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgGrooveParameters::TaskDlgGrooveParameters(ViewProviderGroove *GrooveView)
: TaskDlgSketchBasedParameters(GrooveView)
{
assert(vp);
parameter = new TaskGrooveParameters(static_cast<ViewProviderGroove*>(vp));
Content.push_back(parameter);
}
TaskDlgGrooveParameters::~TaskDlgGrooveParameters()
{
}
//==== calls from the TaskView ===============================================================
void TaskDlgGrooveParameters::open()
{
// a transaction is already open at creation time of the groove
if (!Gui::Command::hasPendingCommand()) {
QString msg = QObject::tr("Edit groove");
Gui::Command::openCommand((const char*)msg.toUtf8());
}
}
void TaskDlgGrooveParameters::clicked(int)
{
}
bool TaskDlgGrooveParameters::accept()
{
parameter->apply();
return true;
}
bool TaskDlgGrooveParameters::reject()
{
// get the support and Sketch
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(vp->getObject());
Sketcher::SketchObject *pcSketch = 0;
if (pcGroove->Sketch.getValue()) {
pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->Sketch.getValue());
}
// role back the done things
Gui::Command::abortCommand();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
// if abort command deleted the object the support is visible again
if (!Gui::Application::Instance->getViewProvider(pcGroove)) {
if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch))
Gui::Application::Instance->getViewProvider(pcSketch)->show();
}
// Body housekeeping
if (ActivePartObject != NULL) {
// Make the new Tip and the previous solid feature visible again
App::DocumentObject* tip = ActivePartObject->Tip.getValue();
App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature();
if (tip != NULL) {
Gui::Application::Instance->getViewProvider(tip)->show();
if ((tip != prev) && (prev != NULL))
Gui::Application::Instance->getViewProvider(prev)->show();
}
}
return true;
}
#include "moc_TaskGrooveParameters.cpp"

View File

@ -1,117 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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 *
* *
******************************************************************************/
#ifndef GUI_TASKVIEW_TaskGrooveParameters_H
#define GUI_TASKVIEW_TaskGrooveParameters_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h>
#include "ViewProviderGroove.h"
#include "TaskSketchBasedParameters.h"
class Ui_TaskGrooveParameters;
namespace App {
class Property;
}
namespace Gui {
class ViewProvider;
}
namespace PartDesignGui {
class TaskGrooveParameters : public TaskSketchBasedParameters
{
Q_OBJECT
public:
TaskGrooveParameters(ViewProviderGroove *GrooveView,QWidget *parent = 0);
~TaskGrooveParameters();
void apply();
private Q_SLOTS:
void onAngleChanged(double);
void onAxisChanged(int);
void onMidplane(bool);
void onReversed(bool);
protected:
void onSelectionChanged(const Gui::SelectionChanges& msg) {}
void changeEvent(QEvent *e);
QString getReferenceAxis(void) const;
double getAngle(void) const;
bool getMidplane(void) const;
bool getReversed(void) const;
const bool updateView() const;
private:
private:
QWidget* proxy;
Ui_TaskGrooveParameters* ui;
};
/// simulation dialog for the TaskView
class TaskDlgGrooveParameters : public TaskDlgSketchBasedParameters
{
Q_OBJECT
public:
TaskDlgGrooveParameters(ViewProviderGroove *GrooveView);
~TaskDlgGrooveParameters();
ViewProviderGroove* getGrooveView() const
{ return static_cast<ViewProviderGroove*>(vp); }
public:
/// is called the TaskView when the dialog is opened
virtual void open();
/// is called by the framework if an button is clicked which has no accept or reject role^M
virtual void clicked(int);
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
<<<<<<< 0973b40e8e489ddbf6455e9a2e80b0520f143b58
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
=======
>>>>>>> Refactored code of SketchBased features to have common code in an abstract superclass
protected:
TaskGrooveParameters *parameter;
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TASKAPPERANCE_H

View File

@ -1,445 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QMessageBox>
# include <QTimer>
#endif
#include "ui_TaskLinearPatternParameters.h"
#include "TaskLinearPatternParameters.h"
#include "TaskMultiTransformParameters.h"
#include "Workbench.h"
#include "ReferenceSelection.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/Part.h>
#include <App/Origin.h>
#include <App/Line.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/ViewProviderOrigin.h>
#include <Mod/PartDesign/App/FeatureLinearPattern.h>
#include <Mod/PartDesign/App/DatumPlane.h>
#include <Mod/PartDesign/App/DatumLine.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskLinearPatternParameters */
TaskLinearPatternParameters::TaskLinearPatternParameters(ViewProviderTransformed *TransformedView,QWidget *parent)
: TaskTransformedParameters(TransformedView, parent)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskLinearPatternParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true);
selectionMode = none;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
TaskLinearPatternParameters::TaskLinearPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout)
: TaskTransformedParameters(parentTask)
{
proxy = new QWidget(parentTask);
ui = new Ui_TaskLinearPatternParameters();
ui->setupUi(proxy);
connect(ui->buttonOK, SIGNAL(pressed()),
parentTask, SLOT(onSubTaskButtonOK()));
QMetaObject::connectSlotsByName(this);
layout->addWidget(proxy);
ui->buttonOK->setEnabled(true);
ui->buttonAddFeature->hide();
ui->buttonRemoveFeature->hide();
ui->listWidgetFeatures->hide();
ui->checkBoxUpdateView->hide();
selectionMode = none;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
void TaskLinearPatternParameters::setupUI()
{
connect(ui->buttonAddFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonAddFeature(bool)));
connect(ui->buttonRemoveFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonRemoveFeature(bool)));
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetFeatures->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onFeatureDeleted()));
ui->listWidgetFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
updateViewTimer = new QTimer(this);
updateViewTimer->setSingleShot(true);
updateViewTimer->setInterval(getUpdateViewTimeout());
connect(updateViewTimer, SIGNAL(timeout()),
this, SLOT(onUpdateViewTimer()));
connect(ui->comboDirection, SIGNAL(activated(int)),
this, SLOT(onDirectionChanged(int)));
connect(ui->checkReverse, SIGNAL(toggled(bool)),
this, SLOT(onCheckReverse(bool)));
connect(ui->spinLength, SIGNAL(valueChanged(double)),
this, SLOT(onLength(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(uint)),
this, SLOT(onOccurrences(uint)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
// Get the feature data
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
std::vector<App::DocumentObject*> originals = pcLinearPattern->Originals.getValues();
// Fill data into dialog elements
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); ++i)
{
if ((*i) != NULL)
ui->listWidgetFeatures->addItem(QString::fromLatin1((*i)->getNameInDocument()));
}
// ---------------------
ui->spinLength->bind(pcLinearPattern->Length);
ui->spinOccurrences->setMaximum(INT_MAX);
ui->spinOccurrences->bind(pcLinearPattern->Occurrences);
ui->comboDirection->setEnabled(true);
ui->checkReverse->setEnabled(true);
ui->spinLength->blockSignals(true);
ui->spinLength->setEnabled(true);
ui->spinLength->setUnit(Base::Unit::Length);
ui->spinLength->blockSignals(false);
ui->spinOccurrences->setEnabled(true);
dirLinks.setCombo(*(ui->comboDirection));
App::DocumentObject* sketch = getSketchObject();
if (!sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId()))
sketch = 0;
this->fillAxisCombo(dirLinks,static_cast<Part::Part2DObject*>(sketch));
updateUI();
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument());
origin->setTemporaryVisibilityAxis(true);
}
}
}
void TaskLinearPatternParameters::updateUI()
{
if (blockUpdate)
return;
blockUpdate = true;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
bool reverse = pcLinearPattern->Reversed.getValue();
double length = pcLinearPattern->Length.getValue();
unsigned occurrences = pcLinearPattern->Occurrences.getValue();
if (dirLinks.setCurrentLink(pcLinearPattern->Direction) == -1){
//failed to set current, because the link isnt in the list yet
dirLinks.addLink(pcLinearPattern->Direction, getRefStr(pcLinearPattern->Direction.getValue(),pcLinearPattern->Direction.getSubValues()));
dirLinks.setCurrentLink(pcLinearPattern->Direction);
}
// Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we
// didn't check for blockUpdate
ui->checkReverse->setChecked(reverse);
ui->spinLength->setValue(length);
ui->spinOccurrences->setValue(occurrences);
blockUpdate = false;
}
void TaskLinearPatternParameters::onUpdateViewTimer()
{
recomputeFeature();
}
void TaskLinearPatternParameters::kickUpdateViewTimer() const
{
updateViewTimer->start();
}
void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (originalSelected(msg)) {
if (selectionMode == addFeature)
ui->listWidgetFeatures->addItem(QString::fromLatin1(msg.pObjectName));
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
exitSelectionMode();
std::vector<std::string> directions;
App::DocumentObject* selObj;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
getReferencedSelection(pcLinearPattern, msg, selObj, directions);
pcLinearPattern->Direction.setValue(selObj, directions);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) {
std::vector<std::string> directions;
App::DocumentObject* selObj;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
getReferencedSelection(pcLinearPattern, msg, selObj, directions);
pcLinearPattern->Direction.setValue(selObj, directions);
recomputeFeature();
updateUI();
}
}
}
void TaskLinearPatternParameters::clearButtons()
{
ui->buttonAddFeature->setChecked(false);
ui->buttonRemoveFeature->setChecked(false);
}
void TaskLinearPatternParameters::onCheckReverse(const bool on) {
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Reversed.setValue(on);
exitSelectionMode();
kickUpdateViewTimer();
}
void TaskLinearPatternParameters::onLength(const double l) {
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Length.setValue(l);
exitSelectionMode();
kickUpdateViewTimer();
}
void TaskLinearPatternParameters::onOccurrences(const uint n) {
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
pcLinearPattern->Occurrences.setValue(n);
exitSelectionMode();
kickUpdateViewTimer();
}
void TaskLinearPatternParameters::onDirectionChanged(int num) {
if (blockUpdate)
return;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
try{
if(dirLinks.getCurrentLink().getValue() == 0){
// enter reference selection mode
hideObject();
showBase();
selectionMode = reference;
Gui::Selection().clearSelection();
addReferenceSelectionGate(true, true);
} else {
exitSelectionMode();
pcLinearPattern->Direction.Paste(dirLinks.getCurrentLink());
}
} catch (Base::Exception &e) {
QMessageBox::warning(0,tr("Error"),QString::fromAscii(e.what()));
}
kickUpdateViewTimer();
}
void TaskLinearPatternParameters::onUpdateView(bool on)
{
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgLinearPatternParameters::accept() but without doCommand
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
std::vector<std::string> directions;
App::DocumentObject* obj;
getDirection(obj, directions);
pcLinearPattern->Direction.setValue(obj,directions);
pcLinearPattern->Reversed.setValue(getReverse());
pcLinearPattern->Length.setValue(getLength());
pcLinearPattern->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
}
void TaskLinearPatternParameters::onFeatureDeleted(void)
{
PartDesign::Transformed* pcTransformed = getObject();
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
originals.erase(originals.begin() + ui->listWidgetFeatures->currentRow());
pcTransformed->Originals.setValues(originals);
ui->listWidgetFeatures->model()->removeRow(ui->listWidgetFeatures->currentRow());
recomputeFeature();
}
void TaskLinearPatternParameters::getDirection(App::DocumentObject*& obj, std::vector<std::string>& sub) const
{
const App::PropertyLinkSub &lnk = dirLinks.getCurrentLink();
obj = lnk.getValue();
sub = lnk.getSubValues();
}
const bool TaskLinearPatternParameters::getReverse(void) const
{
return ui->checkReverse->isChecked();
}
const double TaskLinearPatternParameters::getLength(void) const
{
return ui->spinLength->value().getValue();
}
const unsigned TaskLinearPatternParameters::getOccurrences(void) const
{
return ui->spinOccurrences->value();
}
TaskLinearPatternParameters::~TaskLinearPatternParameters()
{
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->setTemporaryVisibilityMode(false);
}
}
delete ui;
if (proxy)
delete proxy;
}
void TaskLinearPatternParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
void TaskLinearPatternParameters::apply()
{
std::string name = TransformedView->getObject()->getNameInDocument();
std::vector<std::string> directions;
App::DocumentObject* obj;
getDirection(obj, directions);
std::string direction = getPythonStr(obj, directions);
if (!direction.empty() && obj) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = %s", name.c_str(), direction.c_str());
} else {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Direction = None", name.c_str());
}
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),getReverse());
ui->spinLength->apply();
ui->spinOccurrences->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgLinearPatternParameters::TaskDlgLinearPatternParameters(ViewProviderLinearPattern *LinearPatternView)
: TaskDlgTransformedParameters(LinearPatternView)
{
parameter = new TaskLinearPatternParameters(LinearPatternView);
Content.push_back(parameter);
}
//==== calls from the TaskView ===============================================================
bool TaskDlgLinearPatternParameters::accept()
{
<<<<<<< a6aea83ec9ef83d52a06178b32175b3e79f73c65
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
}
=======
parameter->apply();
>>>>>>> PartDesign: make transform parameter dialogs use common base code with other dialogs
return TaskDlgTransformedParameters::accept();
}
#include "moc_TaskLinearPatternParameters.cpp"

View File

@ -1,361 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QMessageBox>
#endif
#include "ui_TaskMirroredParameters.h"
#include "TaskMirroredParameters.h"
#include "TaskMultiTransformParameters.h"
#include "Workbench.h"
#include "ReferenceSelection.h"
#include <App/Application.h>
#include <App/Document.h>
#include <App/Part.h>
#include <App/Plane.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/ViewProviderOrigin.h>
#include <Mod/PartDesign/App/DatumPlane.h>
#include <Mod/PartDesign/App/FeatureMirrored.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskMirroredParameters */
TaskMirroredParameters::TaskMirroredParameters(ViewProviderTransformed *TransformedView, QWidget *parent)
: TaskTransformedParameters(TransformedView, parent)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskMirroredParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true);
selectionMode = none;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
TaskMirroredParameters::TaskMirroredParameters(TaskMultiTransformParameters *parentTask, QLayout *layout)
: TaskTransformedParameters(parentTask)
{
proxy = new QWidget(parentTask);
ui = new Ui_TaskMirroredParameters();
ui->setupUi(proxy);
connect(ui->buttonOK, SIGNAL(pressed()),
parentTask, SLOT(onSubTaskButtonOK()));
QMetaObject::connectSlotsByName(this);
layout->addWidget(proxy);
ui->buttonOK->setEnabled(true);
ui->buttonAddFeature->hide();
ui->buttonRemoveFeature->hide();
ui->listWidgetFeatures->hide();
ui->checkBoxUpdateView->hide();
selectionMode = none;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
void TaskMirroredParameters::setupUI()
{
connect(ui->buttonAddFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonAddFeature(bool)));
connect(ui->buttonRemoveFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonRemoveFeature(bool)));
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetFeatures->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onFeatureDeleted()));
ui->listWidgetFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(ui->comboPlane, SIGNAL(activated(int)),
this, SLOT(onPlaneChanged(int)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
// Get the feature data
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
std::vector<App::DocumentObject*> originals = pcMirrored->Originals.getValues();
// Fill data into dialog elements
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); ++i)
{
if ((*i) != NULL)
ui->listWidgetFeatures->addItem(QString::fromLatin1((*i)->getNameInDocument()));
}
// ---------------------
this->planeLinks.setCombo(*(ui->comboPlane));
ui->comboPlane->setEnabled(true);
App::DocumentObject* sketch = getSketchObject();
if (!sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId()))
sketch = 0;
this->fillPlanesCombo(planeLinks,static_cast<Part::Part2DObject*>(sketch));
updateUI();
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument());
origin->setTemporaryVisibilityAxis(true);
}
}
}
void TaskMirroredParameters::updateUI()
{
if (blockUpdate)
return;
blockUpdate = true;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
if (planeLinks.setCurrentLink(pcMirrored->MirrorPlane) == -1){
//failed to set current, because the link isnt in the list yet
planeLinks.addLink(pcMirrored->MirrorPlane, getRefStr(pcMirrored->MirrorPlane.getValue(),pcMirrored->MirrorPlane.getSubValues()));
planeLinks.setCurrentLink(pcMirrored->MirrorPlane);
}
blockUpdate = false;
}
void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (originalSelected(msg)) {
if (selectionMode == addFeature)
ui->listWidgetFeatures->addItem(QString::fromLatin1(msg.pObjectName));
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
exitSelectionMode();
std::vector<std::string> mirrorPlanes;
App::DocumentObject* selObj;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaseplaneTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[2]) == nullptr) {
std::vector<std::string> planes;
App::DocumentObject* selObj;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
getReferencedSelection(pcMirrored, msg, selObj, planes);
pcMirrored->MirrorPlane.setValue(selObj, planes);
recomputeFeature();
updateUI();
}
}
}
void TaskMirroredParameters::clearButtons()
{
ui->buttonAddFeature->setChecked(false);
ui->buttonRemoveFeature->setChecked(false);
}
void TaskMirroredParameters::onPlaneChanged(int num) {
if (blockUpdate)
return;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
try{
if(planeLinks.getCurrentLink().getValue() == 0){
// enter reference selection mode
hideObject();
showBase();
selectionMode = reference;
Gui::Selection().clearSelection();
addReferenceSelectionGate(false, true);
} else {
exitSelectionMode();
pcMirrored->MirrorPlane.Paste(planeLinks.getCurrentLink());
}
} catch (Base::Exception &e) {
QMessageBox::warning(0,tr("Error"),QString::fromAscii(e.what()));
}
recomputeFeature();
}
void TaskMirroredParameters::onUpdateView(bool on)
{
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgMirroredParameters::accept() but without doCommand
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
std::vector<std::string> mirrorPlanes;
App::DocumentObject* obj;
getMirrorPlane(obj, mirrorPlanes);
pcMirrored->MirrorPlane.setValue(obj,mirrorPlanes);
recomputeFeature();
}
}
void TaskMirroredParameters::onFeatureDeleted(void)
{
PartDesign::Transformed* pcTransformed = getObject();
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
originals.erase(originals.begin() + ui->listWidgetFeatures->currentRow());
pcTransformed->Originals.setValues(originals);
ui->listWidgetFeatures->model()->removeRow(ui->listWidgetFeatures->currentRow());
recomputeFeature();
}
void TaskMirroredParameters::getMirrorPlane(App::DocumentObject*& obj, std::vector<std::string> &sub) const
{
const App::PropertyLinkSub &lnk = planeLinks.getCurrentLink();
obj = lnk.getValue();
sub = lnk.getSubValues();
}
void TaskMirroredParameters::apply()
{
}
TaskMirroredParameters::~TaskMirroredParameters()
{
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->setTemporaryVisibilityMode(false);
}
}
delete ui;
if (proxy)
delete proxy;
}
void TaskMirroredParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgMirroredParameters::TaskDlgMirroredParameters(ViewProviderMirrored *MirroredView)
: TaskDlgTransformedParameters(MirroredView)
{
parameter = new TaskMirroredParameters(MirroredView);
Content.push_back(parameter);
}
//==== calls from the TaskView ===============================================================
bool TaskDlgMirroredParameters::accept()
{
<<<<<<< a6aea83ec9ef83d52a06178b32175b3e79f73c65
std::string name = TransformedView->getObject()->getNameInDocument();
try {
// Handle Originals
if (!TaskDlgTransformedParameters::accept())
return false;
TaskMirroredParameters* mirrorParameter = static_cast<TaskMirroredParameters*>(parameter);
std::vector<std::string> mirrorPlanes;
App::DocumentObject* obj;
mirrorParameter->getMirrorPlane(obj, mirrorPlanes);
std::string mirrorPlane = getPythonStr(obj, mirrorPlanes);
if (!mirrorPlane.empty() && obj) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), mirrorPlane.c_str());
} else {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = None", name.c_str());
}
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
=======
std::string name = vp->getObject()->getNameInDocument();
TaskMirroredParameters* mirrorParameter = static_cast<TaskMirroredParameters*>(parameter);
std::vector<std::string> mirrorPlanes;
App::DocumentObject* obj;
mirrorParameter->getMirrorPlane(obj, mirrorPlanes);
std::string mirrorPlane = getPythonStr(obj, mirrorPlanes);
if (!mirrorPlane.empty() && obj) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = %s", name.c_str(), mirrorPlane.c_str());
} else {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.MirrorPlane = None", name.c_str());
>>>>>>> PartDesign: make transform parameter dialogs use common base code with other dialogs
}
return TaskDlgTransformedParameters::accept();
}
#include "moc_TaskMirroredParameters.cpp"

View File

@ -1,512 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QMessageBox>
#endif
#include "ui_TaskMultiTransformParameters.h"
#include "TaskMultiTransformParameters.h"
#include "TaskMirroredParameters.h"
#include "TaskLinearPatternParameters.h"
#include "TaskPolarPatternParameters.h"
#include "TaskScaledParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Mod/PartDesign/App/FeatureMultiTransform.h>
#include <Mod/PartDesign/App/FeatureMirrored.h>
#include <Mod/PartDesign/App/FeatureLinearPattern.h>
#include <Mod/PartDesign/App/FeaturePolarPattern.h>
#include <Mod/PartDesign/App/FeatureScaled.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskMultiTransformParameters */
TaskMultiTransformParameters::TaskMultiTransformParameters(ViewProviderTransformed *TransformedView,QWidget *parent)
: TaskTransformedParameters(TransformedView, parent), subTask(NULL)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskMultiTransformParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
connect(ui->buttonAddFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonAddFeature(bool)));
connect(ui->buttonRemoveFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonRemoveFeature(bool)));
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetFeatures->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onFeatureDeleted()));
ui->listWidgetFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
// Create a context menu for the listview of transformation features
action = new QAction(tr("Edit"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformEdit()));
ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Delete"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformDelete()));
ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add mirrored transformation"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddMirrored()));
ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add linear pattern"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddLinearPattern()));
ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add polar pattern"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddPolarPattern()));
ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Add scaled transformation"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onTransformAddScaled()));
ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Move up"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onMoveUp()));
ui->listTransformFeatures->addAction(action);
action = new QAction(tr("Move down"), ui->listTransformFeatures);
action->connect(action, SIGNAL(triggered()),
this, SLOT(onMoveDown()));
ui->listTransformFeatures->addAction(action);
ui->listTransformFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
connect(ui->listTransformFeatures, SIGNAL(activated(QModelIndex)),
this, SLOT(onTransformActivated(QModelIndex)));
// Get the transformFeatures data
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
// Fill data into dialog elements
ui->listTransformFeatures->setEnabled(true);
ui->listTransformFeatures->clear();
for (std::vector<App::DocumentObject*>::const_iterator i = transformFeatures.begin(); i != transformFeatures.end(); i++)
{
if ((*i) != NULL)
ui->listTransformFeatures->addItem(QString::fromLatin1((*i)->Label.getValue()));
}
if (transformFeatures.size() > 0) {
ui->listTransformFeatures->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
editHint = false;
} else {
ui->listTransformFeatures->addItem(tr("Right-click to add"));
editHint = true;
}
// Get the Originals data
std::vector<App::DocumentObject*> originals = pcMultiTransform->Originals.getValues();
// Fill data into dialog elements
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); i++)
{
if ((*i) != NULL)
ui->listWidgetFeatures->addItem(QString::fromLatin1((*i)->getNameInDocument()));
}
// ---------------------
}
void TaskMultiTransformParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (originalSelected(msg)) {
if (selectionMode == addFeature)
ui->listWidgetFeatures->addItem(QString::fromLatin1(msg.pObjectName));
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
}
}
void TaskMultiTransformParameters::clearButtons()
{
ui->buttonAddFeature->setChecked(false);
ui->buttonRemoveFeature->setChecked(false);
}
void TaskMultiTransformParameters::onFeatureDeleted(void)
{
PartDesign::Transformed* pcTransformed = getObject();
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
originals.erase(originals.begin() + ui->listWidgetFeatures->currentRow());
pcTransformed->Originals.setValues(originals);
ui->listWidgetFeatures->model()->removeRow(ui->listWidgetFeatures->currentRow());
recomputeFeature();
}
void TaskMultiTransformParameters::closeSubTask()
{
if (subTask) {
exitSelectionMode();
disconnect(ui->checkBoxUpdateView, 0, subTask, 0);
delete subTask;
subTask = NULL;
}
}
void TaskMultiTransformParameters::onTransformDelete()
{
if (editHint) return; // Can't delete the hint...
int row = ui->listTransformFeatures->currentIndex().row();
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
App::DocumentObject* feature = transformFeatures[row];
pcMultiTransform->getDocument()->remObject(feature->getNameInDocument());
closeSubTask();
transformFeatures.erase(transformFeatures.begin() + row);
pcMultiTransform->Transformations.setValues(transformFeatures);
// Note: When the last transformation is deleted, recomputeFeature does nothing, because Transformed::execute()
// says: "No transformations defined, exit silently"
recomputeFeature();
ui->listTransformFeatures->model()->removeRow(row);
ui->listTransformFeatures->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
}
void TaskMultiTransformParameters::onTransformEdit()
{
if (editHint) return; // Can't edit the hint...
closeSubTask(); // For example if user is editing one subTask and then double-clicks on another without OK'ing first
ui->listTransformFeatures->currentItem()->setSelected(true);
int row = ui->listTransformFeatures->currentIndex().row();
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
subFeature = static_cast<PartDesign::Transformed*>(transformFeatures[row]);
if (transformFeatures[row]->getTypeId() == PartDesign::Mirrored::getClassTypeId())
subTask = new TaskMirroredParameters(this, ui->verticalLayout);
else if (transformFeatures[row]->getTypeId() == PartDesign::LinearPattern::getClassTypeId())
subTask = new TaskLinearPatternParameters(this, ui->verticalLayout);
else if (transformFeatures[row]->getTypeId() == PartDesign::PolarPattern::getClassTypeId())
subTask = new TaskPolarPatternParameters(this, ui->verticalLayout);
else if (transformFeatures[row]->getTypeId() == PartDesign::Scaled::getClassTypeId())
subTask = new TaskScaledParameters(this, ui->verticalLayout);
else
return; // TODO: Show an error?
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
subTask, SLOT(onUpdateView(bool)));
}
void TaskMultiTransformParameters::onTransformActivated(const QModelIndex& index) {
onTransformEdit();
}
void TaskMultiTransformParameters::onTransformAddMirrored()
{
closeSubTask();
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("Mirrored");
Gui::Command::openCommand("Mirrored");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Mirrored\",\"%s\")",newFeatName.c_str());
//Gui::Command::updateActive();
App::DocumentObject* sketch = getSketchObject();
if (sketch)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])",
newFeatName.c_str(), sketch->getNameInDocument());
finishAdd(newFeatName);
}
void TaskMultiTransformParameters::onTransformAddLinearPattern()
{
closeSubTask();
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("LinearPattern");
Gui::Command::openCommand("LinearPattern");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::LinearPattern\",\"%s\")",newFeatName.c_str());
//Gui::Command::updateActive();
App::DocumentObject* sketch = getSketchObject();
if (sketch)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])",
newFeatName.c_str(), sketch->getNameInDocument());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Length = 100", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str());
finishAdd(newFeatName);
}
void TaskMultiTransformParameters::onTransformAddPolarPattern()
{
closeSubTask();
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("PolarPattern");
Gui::Command::openCommand("PolarPattern");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::PolarPattern\",\"%s\")",newFeatName.c_str());
//Gui::Command::updateActive();
App::DocumentObject* sketch = getSketchObject();
if (sketch)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])",
newFeatName.c_str(), sketch->getNameInDocument());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Angle = 360", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str());
finishAdd(newFeatName);
}
void TaskMultiTransformParameters::onTransformAddScaled()
{
closeSubTask();
std::string newFeatName = TransformedView->getObject()->getDocument()->getUniqueObjectName("Scaled");
Gui::Command::openCommand("Scaled");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject(\"PartDesign::Scaled\",\"%s\")",newFeatName.c_str());
//Gui::Command::updateActive();
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Factor = 2", newFeatName.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Occurrences = 2", newFeatName.c_str());
finishAdd(newFeatName);
}
void TaskMultiTransformParameters::finishAdd(std::string &newFeatName)
{
//Gui::Command::updateActive();
//Gui::Command::copyVisual(newFeatName.c_str(), "ShapeColor", getOriginals().front()->getNameInDocument().c_str());
//Gui::Command::copyVisual(newFeatName.c_str(), "DisplayMode", getOriginals().front()->getNameInDocument().c_str());
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
if (editHint) {
// Remove hint, first feature is being added
ui->listTransformFeatures->model()->removeRow(0);
}
int row = ui->listTransformFeatures->currentIndex().row();
if (row < 0) {
// Happens when first row (first transformation) is created
// Hide all the originals now (hiding them in Command.cpp presents the user with an empty screen!)
hideBase();
}
// Insert new transformation after the selected row
// This means that in order to insert at the beginning, the user has to use "Move Up" in the menu
App::DocumentObject* newFeature = pcMultiTransform->getDocument()->getObject(newFeatName.c_str());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
if (row == ui->listTransformFeatures->model()->rowCount() - 1) {
// Note: Inserts always happen before the specified iterator so in order to append at the
// end we need to use push_back() and append()
transformFeatures.push_back(newFeature);
ui->listTransformFeatures->addItem(QString::fromLatin1(newFeature->Label.getValue()));
ui->listTransformFeatures->setCurrentRow(row+1, QItemSelectionModel::ClearAndSelect);
} else {
// Note: The feature tree always seems to append to the end, no matter what we say here
transformFeatures.insert(transformFeatures.begin() + row + 1, newFeature);
ui->listTransformFeatures->insertItem(row + 1, QString::fromLatin1(newFeature->Label.getValue()));
ui->listTransformFeatures->setCurrentRow(row + 1, QItemSelectionModel::ClearAndSelect);
}
pcMultiTransform->Transformations.setValues(transformFeatures);
recomputeFeature();
// Set state to hidden - only the MultiTransform should be visible
Gui::Command::doCommand(
Gui::Command::Doc,"Gui.activeDocument().getObject(\"%s\").Visibility=False", newFeatName.c_str());
editHint = false;
onTransformEdit();
}
void TaskMultiTransformParameters::moveTransformFeature(const int increment)
{
int row = ui->listTransformFeatures->currentIndex().row();
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
App::DocumentObject* feature = transformFeatures[row];
transformFeatures.erase(transformFeatures.begin() + row);
QListWidgetItem* item = new QListWidgetItem(*(ui->listTransformFeatures->item(row)));
ui->listTransformFeatures->model()->removeRow(row);
// After this operation, if we were to insert at index row again, things will remain unchanged
row += increment;
if (row < 0)
row = 0;
if (row >= ui->listTransformFeatures->model()->rowCount()) {
// Note: Inserts always happen before the specified iterator so in order to append at the
// end we need to use push_back() and append()
transformFeatures.push_back(feature);
ui->listTransformFeatures->addItem(item);
ui->listTransformFeatures->setCurrentRow(row, QItemSelectionModel::ClearAndSelect);
} else {
transformFeatures.insert(transformFeatures.begin() + row, feature);
ui->listTransformFeatures->insertItem(row, item);
ui->listTransformFeatures->setCurrentRow(row, QItemSelectionModel::ClearAndSelect);
}
pcMultiTransform->Transformations.setValues(transformFeatures);
recomputeFeature();
}
void TaskMultiTransformParameters::onMoveUp()
{
moveTransformFeature(-1);
}
void TaskMultiTransformParameters::onMoveDown()
{
moveTransformFeature(+1);
}
void TaskMultiTransformParameters::onSubTaskButtonOK() {
closeSubTask();
}
void TaskMultiTransformParameters::onUpdateView(bool on)
{
blockUpdate = !on;
if (on)
recomputeFeature();
}
const std::vector<App::DocumentObject*> TaskMultiTransformParameters::getTransformFeatures(void) const
{
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(TransformedView->getObject());
return pcMultiTransform->Transformations.getValues();
}
void TaskMultiTransformParameters::apply()
{
}
TaskMultiTransformParameters::~TaskMultiTransformParameters()
{
closeSubTask();
delete ui;
if (proxy)
delete proxy;
}
void TaskMultiTransformParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgMultiTransformParameters::TaskDlgMultiTransformParameters(ViewProviderMultiTransform *MultiTransformView)
: TaskDlgTransformedParameters(MultiTransformView)
{
parameter = new TaskMultiTransformParameters(MultiTransformView);
Content.push_back(parameter);
}
//==== calls from the TaskView ===============================================================
bool TaskDlgMultiTransformParameters::accept()
{
<<<<<<< a6aea83ec9ef83d52a06178b32175b3e79f73c65
std::string name = TransformedView->getObject()->getNameInDocument();
try {
//Gui::Command::openCommand("MultiTransform changed");
// Handle Originals
if (!TaskDlgTransformedParameters::accept())
return false;
TaskMultiTransformParameters* mtParameter = static_cast<TaskMultiTransformParameters*>(parameter);
std::vector<App::DocumentObject*> transformFeatures = mtParameter->getTransformFeatures();
std::stringstream str;
str << "App.ActiveDocument." << name.c_str() << ".Transformations = [";
for (std::vector<App::DocumentObject*>::const_iterator it = transformFeatures.begin(); it != transformFeatures.end(); it++)
{
if ((*it) != NULL)
str << "App.ActiveDocument." << (*it)->getNameInDocument() << ",";
}
str << "]";
Gui::Command::runCommand(Gui::Command::Doc,str.str().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
=======
std::string name = vp->getObject()->getNameInDocument();
// Set up transformations
TaskMultiTransformParameters* mtParameter = static_cast<TaskMultiTransformParameters*>(parameter);
std::vector<App::DocumentObject*> transformFeatures = mtParameter->getTransformFeatures();
std::stringstream str;
str << "App.ActiveDocument." << name.c_str() << ".Transformations = [";
for (std::vector<App::DocumentObject*>::const_iterator it = transformFeatures.begin(); it != transformFeatures.end(); it++)
{
if ((*it) != NULL)
str << "App.ActiveDocument." << (*it)->getNameInDocument() << ",";
>>>>>>> PartDesign: make transform parameter dialogs use common base code with other dialogs
}
str << "]";
Gui::Command::runCommand(Gui::Command::Doc,str.str().c_str());
return TaskDlgFeatureParameters::accept ();
}
bool TaskDlgMultiTransformParameters::reject()
{
// Get objects before view is invalidated
// For the same reason we can't delegate showing the originals to TaskDlgTransformedParameters::reject()
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(vp->getObject());
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
// Delete the transformation features - must happen before abortCommand()!
for (std::vector<App::DocumentObject*>::const_iterator it = transformFeatures.begin(); it != transformFeatures.end(); ++it)
{
if ((*it) != NULL)
Gui::Command::doCommand(
Gui::Command::Doc,"App.ActiveDocument.removeObject(\"%s\")", (*it)->getNameInDocument());
}
return TaskDlgTransformedParameters::reject();
}
#include "moc_TaskMultiTransformParameters.cpp"

View File

@ -1,507 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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"
#ifndef _PreComp_
# include <sstream>
# include <QRegExp>
# include <QTextStream>
# include <QMessageBox>
# include <Precision.hxx>
#endif
#include "ui_TaskPadParameters.h"
#include "TaskPadParameters.h"
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeaturePad.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include "TaskSketchBasedParameters.h"
#include "ReferenceSelection.h"
#include "Workbench.h"
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskPadParameters */
TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView,bool newObj, QWidget *parent)
: TaskSketchBasedParameters(PadView, parent, "PartDesign_Pad",tr("Pad parameters"))
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskPadParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
connect(ui->lengthEdit, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
this, SLOT(onMidplane(bool)));
connect(ui->checkBoxReversed, SIGNAL(toggled(bool)),
this, SLOT(onReversed(bool)));
connect(ui->lengthEdit2, SIGNAL(valueChanged(double)),
this, SLOT(onLength2Changed(double)));
connect(ui->spinOffset, SIGNAL(valueChanged(double)),
this, SLOT(onOffsetChanged(double)));
connect(ui->changeMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(onModeChanged(int)));
connect(ui->buttonFace, SIGNAL(clicked()),
this, SLOT(onButtonFace()));
connect(ui->lineFaceName, SIGNAL(textEdited(QString)),
this, SLOT(onFaceName(QString)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
this->groupLayout()->addWidget(proxy);
// Temporarily prevent unnecessary feature recomputes
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->spinOffset->blockSignals(true);
ui->checkBoxMidplane->blockSignals(true);
ui->checkBoxReversed->blockSignals(true);
ui->buttonFace->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
// set the history path
ui->lengthEdit->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PadLength"));
ui->lengthEdit2->setParamGrpPath(QByteArray("User parameter:BaseApp/History/PadLength2"));
// Get the feature data
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
Base::Quantity l = pcPad->Length.getQuantityValue();
bool midplane = pcPad->Midplane.getValue();
bool reversed = pcPad->Reversed.getValue();
Base::Quantity l2 = pcPad->Length2.getQuantityValue();
double off = pcPad->Offset.getValue();
int index = pcPad->Type.getValue(); // must extract value here, clear() kills it!
App::DocumentObject* obj = pcPad->UpToFace.getValue();
std::vector<std::string> subStrings = pcPad->UpToFace.getSubValues();
std::string upToFace;
int faceId = -1;
if ((obj != NULL) && !subStrings.empty()) {
upToFace = subStrings.front();
if (upToFace.substr(0,4) == "Face")
faceId = std::atoi(&upToFace[4]);
}
// Fill data into dialog elements
ui->lengthEdit->setMinimum(0);
ui->lengthEdit->setMaximum(INT_MAX);
ui->lengthEdit->setValue(l);
ui->lengthEdit2->setMinimum(0);
ui->lengthEdit2->setMaximum(INT_MAX);
ui->lengthEdit2->setValue(l2);
ui->spinOffset->setMaximum(INT_MAX);
ui->spinOffset->setMinimum(-INT_MAX);
ui->spinOffset->setValue(off);
// Bind input fields to properties
ui->lengthEdit->bind(pcPad->Length);
ui->lengthEdit2->bind(pcPad->Length2);
ui->checkBoxMidplane->setChecked(midplane);
// According to bug #0000521 the reversed option
// shouldn't be de-activated if the pad has a support face
ui->checkBoxReversed->setChecked(reversed);
if ((obj != NULL) && PartDesign::Feature::isDatum(obj))
ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()));
else if (faceId >= 0)
ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()) + QString::fromAscii(":") + tr("Face") +
QString::number(faceId));
else
ui->lineFaceName->setText(tr("No face selected"));
ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str()));
ui->changeMode->clear();
ui->changeMode->insertItem(0, tr("Dimension"));
ui->changeMode->insertItem(1, tr("To last"));
ui->changeMode->insertItem(2, tr("To first"));
ui->changeMode->insertItem(3, tr("Up to face"));
ui->changeMode->insertItem(4, tr("Two dimensions"));
ui->changeMode->setCurrentIndex(index);
// activate and de-activate dialog elements as appropriate
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->spinOffset->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
ui->buttonFace->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
updateUI(index);
// if it is a newly created object use the last value of the history
if(newObj){
ui->lengthEdit->setToLastUsedValue();
ui->lengthEdit->selectNumber();
ui->lengthEdit2->setToLastUsedValue();
ui->lengthEdit2->selectNumber();
}
}
void TaskPadParameters::updateUI(int index)
{
if (index == 0) { // dimension
ui->lengthEdit->setVisible(true);
ui->lengthEdit->setEnabled(true);
ui->lengthEdit->selectNumber();
ui->labelLength->setVisible(true);
ui->spinOffset->setVisible(false);
ui->spinOffset->setEnabled(false);
ui->labelOffset->setVisible(false);
// Make sure that the spin box has the focus to get key events
// Calling setFocus() directly doesn't work because the spin box is not
// yet visible.
QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection);
ui->checkBoxMidplane->setEnabled(true);
// Reverse only makes sense if Midplane is not true
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked());
ui->labelLength2->setVisible(false);
ui->lengthEdit2->setVisible(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 1 || index == 2) { // up to first/last
ui->lengthEdit->setVisible(false);
ui->lengthEdit->setEnabled(false);
ui->labelLength->setVisible(false);
ui->spinOffset->setVisible(true);
ui->spinOffset->setEnabled(true);
ui->labelOffset->setVisible(true);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(true);
ui->labelLength2->setVisible(false);
ui->lengthEdit2->setVisible(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 3) { // up to face
ui->lengthEdit->setVisible(false);
ui->lengthEdit->setEnabled(false);
ui->labelLength->setVisible(false);
ui->spinOffset->setVisible(true);
ui->spinOffset->setEnabled(true);
ui->labelOffset->setVisible(true);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false);
ui->labelLength2->setVisible(false);
ui->lengthEdit2->setVisible(false);
ui->lengthEdit2->setEnabled(false);
ui->buttonFace->setEnabled(true);
ui->lineFaceName->setEnabled(true);
QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection);
// Go into reference selection mode if no face has been selected yet
if (ui->lineFaceName->text().isEmpty() || (ui->lineFaceName->text() == tr("No face selected")))
onButtonFace(true);
} else { // two dimensions
ui->lengthEdit->setEnabled(true);
ui->lengthEdit->setVisible(true);
ui->lengthEdit->selectNumber();
QMetaObject::invokeMethod(ui->lengthEdit, "setFocus", Qt::QueuedConnection);
ui->labelLength->setVisible(true);
ui->spinOffset->setVisible(false);
ui->spinOffset->setEnabled(false);
ui->labelOffset->setVisible(false);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false);
ui->labelLength2->setVisible(true);
ui->lengthEdit2->setVisible(true);
ui->lengthEdit2->setEnabled(true);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
}
}
void TaskPadParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
QString refText = onAddSelection(msg);
if (refText.length() != 0) {
ui->lineFaceName->blockSignals(true);
ui->lineFaceName->setText(refText);
ui->lineFaceName->setProperty("FaceName", QByteArray(msg.pSubName));
ui->lineFaceName->blockSignals(false);
// Turn off reference selection mode
onButtonFace(false);
} else {
ui->lineFaceName->blockSignals(true);
ui->lineFaceName->setText(tr("No face selected"));
ui->lineFaceName->setProperty("FaceName", QByteArray());
ui->lineFaceName->blockSignals(false);
}
}
else if (msg.Type == Gui::SelectionChanges::ClrSelection) {
ui->lineFaceName->blockSignals(true);
ui->lineFaceName->setText(tr(""));
ui->lineFaceName->setProperty("FaceName", QByteArray());
ui->lineFaceName->blockSignals(false);
}
}
void TaskPadParameters::onLengthChanged(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Length.setValue(len);
recomputeFeature();
}
void TaskPadParameters::onMidplane(bool on)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Midplane.setValue(on);
ui->checkBoxReversed->setEnabled(!on);
recomputeFeature();
}
void TaskPadParameters::onReversed(bool on)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Reversed.setValue(on);
recomputeFeature();
}
void TaskPadParameters::onLength2Changed(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Length2.setValue(len);
recomputeFeature();
}
void TaskPadParameters::onOffsetChanged(double len)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
pcPad->Offset.setValue(len);
recomputeFeature();
}
void TaskPadParameters::onModeChanged(int index)
{
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(vp->getObject());
switch (index) {
case 0:
pcPad->Type.setValue("Length");
// Avoid error message
if (ui->lengthEdit->value() < Precision::Confusion())
ui->lengthEdit->setValue(5.0);
break;
case 1: pcPad->Type.setValue("UpToLast"); break;
case 2: pcPad->Type.setValue("UpToFirst"); break;
case 3: pcPad->Type.setValue("UpToFace"); break;
default: pcPad->Type.setValue("TwoLengths");
}
updateUI(index);
recomputeFeature();
}
void TaskPadParameters::onButtonFace(const bool pressed)
{
TaskSketchBasedParameters::onSelectReference(pressed, false, true, false);
// Update button if onButtonFace() is called explicitly
ui->buttonFace->setChecked(pressed);
}
void TaskPadParameters::onFaceName(const QString& text)
{
ui->lineFaceName->setProperty("FaceName", TaskSketchBasedParameters::onFaceName(text));
}
double TaskPadParameters::getLength(void) const
{
return ui->lengthEdit->value().getValue();
}
bool TaskPadParameters::getReversed(void) const
{
return ui->checkBoxReversed->isChecked();
}
bool TaskPadParameters::getMidplane(void) const
{
return ui->checkBoxMidplane->isChecked();
}
double TaskPadParameters::getLength2(void) const
{
return ui->lengthEdit2->value().getValue();
}
double TaskPadParameters::getOffset(void) const
{
return ui->spinOffset->value();
}
int TaskPadParameters::getMode(void) const
{
return ui->changeMode->currentIndex();
}
QString TaskPadParameters::getFaceName(void) const
{
if (getMode() == 3) {
QString faceName = ui->lineFaceName->property("FaceName").toString();
if (!faceName.isEmpty()) {
return getFaceReference(ui->lineFaceName->text(), faceName);
}
}
return QString();
}
TaskPadParameters::~TaskPadParameters()
{
delete ui;
}
void TaskPadParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->lengthEdit->blockSignals(true);
ui->lengthEdit2->blockSignals(true);
ui->spinOffset->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
int index = ui->changeMode->currentIndex();
ui->retranslateUi(proxy);
ui->changeMode->clear();
ui->changeMode->addItem(tr("Dimension"));
ui->changeMode->addItem(tr("To last"));
ui->changeMode->addItem(tr("To first"));
ui->changeMode->addItem(tr("Up to face"));
ui->changeMode->addItem(tr("Two dimensions"));
ui->changeMode->setCurrentIndex(index);
QStringList parts = ui->lineFaceName->text().split(QChar::fromAscii(':'));
QByteArray upToFace = ui->lineFaceName->property("FaceName").toByteArray();
int faceId = -1;
bool ok = false;
if (upToFace.indexOf("Face") == 0) {
faceId = upToFace.remove(0,4).toInt(&ok);
}
#if QT_VERSION >= 0x040700
ui->lineFaceName->setPlaceholderText(tr("No face selected"));
#endif
ui->lineFaceName->setText(ok ?
parts[0] + QString::fromAscii(":") + tr("Face") + QString::number(faceId) :
QString());
ui->lengthEdit->blockSignals(false);
ui->lengthEdit2->blockSignals(false);
ui->spinOffset->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
}
}
void TaskPadParameters::saveHistory(void)
{
// save the user values to history
ui->lengthEdit->pushToHistory();
ui->lengthEdit2->pushToHistory();
}
void TaskPadParameters::apply()
{
std::string name = vp->getObject()->getNameInDocument();
const char * cname = name.c_str();
ui->lengthEdit->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",cname,getReversed()?1:0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",cname,getMidplane()?1:0);
ui->lengthEdit2->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",cname,getMode());
QString facename = getFaceName();
if (!facename.isEmpty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s",
cname, facename.toLatin1().data());
} else {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", cname);
}
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Offset = %f", name.c_str(), getOffset());
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgPadParameters::TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj)
: TaskDlgSketchBasedParameters(PadView)
{
assert(PadView);
parameter = new TaskPadParameters(static_cast<ViewProviderPad*>(PadView));
Content.push_back(parameter);
}
TaskDlgPadParameters::~TaskDlgPadParameters()
{
}
//==== calls from the TaskView ===============================================================
bool TaskDlgPadParameters::accept()
{
// save the history
parameter->saveHistory();
parameter->apply();
<<<<<<< b551f892abed242e90afa77240bbdd7dcf7fc45c
try {
//Gui::Command::openCommand("Pad changed");
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
}
return true;
=======
return TaskDlgSketchBasedParameters::accept();
>>>>>>> PartDesignGui: Make DressUp and SketchSupport propertie dialogs use common accept() structure
}
#include "moc_TaskPadParameters.cpp"

View File

@ -1,121 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskPadParameters_H
#define GUI_TASKVIEW_TaskPadParameters_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h>
#include "TaskSketchBasedParameters.h"
#include "ViewProviderPad.h"
class Ui_TaskPadParameters;
namespace App {
class Property;
}
namespace Gui {
class ViewProvider;
}
namespace PartDesignGui {
class TaskPadParameters : public TaskSketchBasedParameters
{
Q_OBJECT
public:
TaskPadParameters(ViewProviderPad *PadView,bool newObj=false,QWidget *parent = 0);
~TaskPadParameters();
const bool updateView() const;
void saveHistory(void);
void apply();
private Q_SLOTS:
void onLengthChanged(double);
void onMidplane(bool);
void onReversed(bool);
void onLength2Changed(double);
void onModeChanged(int);
void onButtonFace(const bool pressed = true);
void onFaceName(const QString& text);
protected:
void changeEvent(QEvent *e);
private:
int getMode(void) const;
double getLength(void) const;
double getLength2(void) const;
bool getReversed(void) const;
bool getMidplane(void) const;
QByteArray getFaceName(void) const;
void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI(int index);
private:
QWidget* proxy;
Ui_TaskPadParameters* ui;
};
/// simulation dialog for the TaskView
class TaskDlgPadParameters : public TaskDlgSketchBasedParameters
{
Q_OBJECT
public:
TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj=false);
~TaskDlgPadParameters();
ViewProviderPad* getPadView() const
{ return static_cast<ViewProviderPad*>(vp); }
public:
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
/// is called by the framework if the dialog is rejected (Cancel)
<<<<<<< 0973b40e8e489ddbf6455e9a2e80b0520f143b58
virtual bool reject();
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
=======
>>>>>>> Refactored code of SketchBased features to have common code in an abstract superclass
protected:
TaskPadParameters *parameter;
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TASKAPPERANCE_H

View File

@ -1,453 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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"
#ifndef _PreComp_
# include <sstream>
# include <QRegExp>
# include <QTextStream>
# include <Precision.hxx>
#endif
#include "ui_TaskPocketParameters.h"
#include "TaskPocketParameters.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeaturePocket.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include "TaskSketchBasedParameters.h"
#include "ReferenceSelection.h"
#include "Workbench.h"
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskPocketParameters */
TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent)
: TaskSketchBasedParameters(PocketView, parent, "PartDesign_Pocket",tr("Pocket parameters"))
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskPocketParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
connect(ui->pocketLength, SIGNAL(valueChanged(double)),
this, SLOT(onLengthChanged(double)));
connect(ui->spinOffset, SIGNAL(valueChanged(double)),
this, SLOT(onOffsetChanged(double)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
this, SLOT(onMidplaneChanged(bool)));
connect(ui->checkBoxReversed, SIGNAL(toggled(bool)),
this, SLOT(onReversedChanged(bool)));
connect(ui->changeMode, SIGNAL(currentIndexChanged(int)),
this, SLOT(onModeChanged(int)));
connect(ui->buttonFace, SIGNAL(pressed()),
this, SLOT(onButtonFace()));
connect(ui->lineFaceName, SIGNAL(textEdited(QString)),
this, SLOT(onFaceName(QString)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
this->groupLayout()->addWidget(proxy);
// Temporarily prevent unnecessary feature recomputes
ui->pocketLength->blockSignals(true);
ui->spinOffset->blockSignals(true);
ui->checkBoxMidplane->blockSignals(true);
ui->checkBoxReversed->blockSignals(true);
ui->buttonFace->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
// Get the feature data
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
double l = pcPocket->Length.getValue();
double off = pcPocket->Offset.getValue();
bool midplane = pcPocket->Midplane.getValue();
bool reversed = pcPocket->Reversed.getValue();
int index = pcPocket->Type.getValue(); // must extract value here, clear() kills it!
App::DocumentObject* obj = pcPocket->UpToFace.getValue();
std::vector<std::string> subStrings = pcPocket->UpToFace.getSubValues();
std::string upToFace;
int faceId = -1;
if ((obj != NULL) && !subStrings.empty()) {
upToFace = subStrings.front();
if (upToFace.substr(0,4) == "Face")
faceId = std::atoi(&upToFace[4]);
}
// Fill data into dialog elements
ui->pocketLength->setMinimum(0);
ui->pocketLength->setMaximum(INT_MAX);
ui->pocketLength->setValue(l);
ui->spinOffset->setMinimum(-INT_MAX);
ui->spinOffset->setMaximum(INT_MAX);
ui->spinOffset->setValue(off);
ui->checkBoxMidplane->setChecked(midplane);
ui->checkBoxReversed->setChecked(reversed);
if ((obj != NULL) && PartDesign::Feature::isDatum(obj))
ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()));
else if (faceId >= 0)
ui->lineFaceName->setText(QString::fromAscii(obj->getNameInDocument()) + QString::fromAscii(":") + tr("Face") +
QString::number(faceId));
else
ui->lineFaceName->setText(tr("No face selected"));
ui->lineFaceName->setProperty("FaceName", QByteArray(upToFace.c_str()));
ui->changeMode->clear();
ui->changeMode->insertItem(0, tr("Dimension"));
ui->changeMode->insertItem(1, tr("Through all"));
ui->changeMode->insertItem(2, tr("To first"));
ui->changeMode->insertItem(3, tr("Up to face"));
ui->changeMode->setCurrentIndex(index);
// Bind input fields to properties
ui->pocketLength->bind(pcPocket->Length);
ui->pocketLength->blockSignals(false);
ui->spinOffset->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
ui->buttonFace->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
ui->checkBoxReversed->setVisible(true);
updateUI(index);
//// check if the sketch has support
//Sketcher::SketchObject *pcSketch;
//if (pcPocket->Sketch.getValue()) {
// pcSketch = static_cast<Sketcher::SketchObject*>(pcPocket->Sketch.getValue());
// if (pcSketch->Support.getValue())
// // in case of sketch with support, reverse makes no sense (goes into the part)
// ui->checkBoxReversed->setEnabled(0);
// else
// ui->checkBoxReversed->setChecked(reversed);
//}
}
void TaskPocketParameters::updateUI(int index)
{
if (index == 0) { // Only this option requires a numeric value // Dimension
ui->pocketLength->setVisible(true);
ui->pocketLength->setEnabled(true);
ui->pocketLength->selectAll();
QMetaObject::invokeMethod(ui->pocketLength, "setFocus", Qt::QueuedConnection);
ui->spinOffset->setVisible(false);
ui->spinOffset->setEnabled(false);
ui->spinOffset->setEnabled(false);
ui->checkBoxMidplane->setEnabled(true);
// Reverse only makes sense if Midplane is not true
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked()); // Will flip direction of dimension
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 1) { // Through all
ui->checkBoxMidplane->setEnabled(true);
ui->checkBoxReversed->setEnabled(!ui->checkBoxMidplane->isChecked()); // Will flip direction of through all
ui->pocketLength->setVisible(false);
ui->pocketLength->setEnabled(false);
ui->spinOffset->setVisible(false);
ui->spinOffset->setVisible(false);
ui->spinOffset->setEnabled(false);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 2) { // Neither value nor face required // To First
ui->pocketLength->setEnabled(false);
ui->pocketLength->setVisible(false);
ui->checkBoxMidplane->setEnabled(false); // Can't have a midplane to a single face
ui->checkBoxReversed->setEnabled(false); // Will change the direction it seeks for its first face?
// Doesnt work so is currently disabled. Fix probably lies
// somwhere in IF block on line 125 of FeaturePocket.cpp
ui->labelLength->setVisible(false);
ui->spinOffset->setVisible(true);
ui->spinOffset->setEnabled(true);
ui->labelOffset->setVisible(true);
ui->buttonFace->setEnabled(false);
ui->lineFaceName->setEnabled(false);
onButtonFace(false);
} else if (index == 3) { // Only this option requires to select a face // Up to face
ui->pocketLength->setEnabled(false);
ui->pocketLength->setVisible(false);
ui->labelLength->setVisible(false);
ui->spinOffset->setVisible(true);
ui->spinOffset->setEnabled(true);
ui->labelOffset->setVisible(true);
ui->checkBoxMidplane->setEnabled(false);
ui->checkBoxReversed->setEnabled(false); // No need for reverse since user-chosen face will dtermine direction
ui->buttonFace->setEnabled(true);
ui->lineFaceName->setEnabled(true);
QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection);
// Go into reference selection mode if no face has been selected yet
if (ui->lineFaceName->text().isEmpty() || (ui->lineFaceName->text() == tr("No face selected")))
onButtonFace(true);
}
}
void TaskPocketParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
QString refText = onAddSelection(msg);
if (refText.length() > 0) {
ui->lineFaceName->blockSignals(true);
ui->lineFaceName->setText(refText);
ui->lineFaceName->setProperty("FaceName", QByteArray(msg.pSubName));
ui->lineFaceName->blockSignals(false);
// Turn off reference selection mode
onButtonFace(false);
} else {
ui->lineFaceName->blockSignals(true);
ui->lineFaceName->setText(tr("No face selected"));
ui->lineFaceName->setProperty("FaceName", QByteArray());
ui->lineFaceName->blockSignals(false);
}
}
else if (msg.Type == Gui::SelectionChanges::ClrSelection) {
ui->lineFaceName->blockSignals(true);
ui->lineFaceName->setText(tr("No face selected"));
ui->lineFaceName->setProperty("FaceName", QByteArray());
ui->lineFaceName->blockSignals(false);
}
}
void TaskPocketParameters::onLengthChanged(double len)
{
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
pcPocket->Length.setValue(len);
recomputeFeature();
}
void TaskPocketParameters::onOffsetChanged(double len)
{
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
pcPocket->Offset.setValue(len);
recomputeFeature();
}
void TaskPocketParameters::onMidplaneChanged(bool on)
{
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
pcPocket->Midplane.setValue(on);
ui->checkBoxReversed->setEnabled(!on);
recomputeFeature();
}
void TaskPocketParameters::onReversedChanged(bool on)
{
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
pcPocket->Reversed.setValue(on);
recomputeFeature();
}
void TaskPocketParameters::onModeChanged(int index)
{
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(vp->getObject());
switch (index) {
case 0:
// Why? See below for "UpToFace"
pcPocket->Type.setValue("Length");
if (oldLength < Precision::Confusion())
oldLength = 5.0;
pcPocket->Length.setValue(oldLength);
ui->pocketLength->setValue(oldLength);
break;
case 1:
oldLength = pcPocket->Length.getValue();
pcPocket->Type.setValue("ThroughAll");
break;
case 2:
oldLength = pcPocket->Length.getValue();
pcPocket->Type.setValue("UpToFirst");
break;
case 3:
// Because of the code at the begining of Pocket::execute() which is used to detect
// broken legacy parts, we must set the length to zero here!
oldLength = pcPocket->Length.getValue();
pcPocket->Type.setValue("UpToFace");
pcPocket->Length.setValue(0.0);
ui->pocketLength->setValue(0.0);
break;
default:
pcPocket->Type.setValue("Length");
}
updateUI(index);
recomputeFeature();
}
void TaskPocketParameters::onButtonFace(const bool pressed) {
TaskSketchBasedParameters::onSelectReference(pressed, false, true, false);
// Update button if onButtonFace() is called explicitly
ui->buttonFace->setChecked(pressed);
}
void TaskPocketParameters::onFaceName(const QString& text)
{
ui->lineFaceName->setProperty("FaceName", TaskSketchBasedParameters::onFaceName(text));
}
double TaskPocketParameters::getLength(void) const
{
return ui->pocketLength->value().getValue();
}
double TaskPocketParameters::getOffset(void) const
{
return ui->spinOffset->value();
}
bool TaskPocketParameters::getReversed(void) const
{
return ui->checkBoxReversed->isChecked();
}
int TaskPocketParameters::getMode(void) const
{
return ui->changeMode->currentIndex();
}
QString TaskPocketParameters::getFaceName(void) const
{
// TODO Make it return None rather than empty string (2015-11-03, Fat-Zer)
if (getMode() == 3) {
QString faceName = ui->lineFaceName->property("FaceName").toString();
if (!faceName.isEmpty()) {
return getFaceReference(ui->lineFaceName->text(), faceName);
}
}
return QString ();
}
TaskPocketParameters::~TaskPocketParameters()
{
delete ui;
}
void TaskPocketParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->pocketLength->blockSignals(true);
ui->spinOffset->blockSignals(true);
ui->lineFaceName->blockSignals(true);
ui->changeMode->blockSignals(true);
int index = ui->changeMode->currentIndex();
ui->retranslateUi(proxy);
ui->changeMode->clear();
ui->changeMode->addItem(tr("Dimension"));
ui->changeMode->addItem(tr("Through all"));
ui->changeMode->addItem(tr("To first"));
ui->changeMode->addItem(tr("Up to face"));
ui->changeMode->setCurrentIndex(index);
QStringList parts = ui->lineFaceName->text().split(QChar::fromAscii(':'));
QByteArray upToFace = ui->lineFaceName->property("FaceName").toByteArray();
int faceId = -1;
bool ok = false;
if (upToFace.indexOf("Face") == 0) {
faceId = upToFace.remove(0,4).toInt(&ok);
}
ui->lineFaceName->setText(ok ?
parts[0] + QString::fromAscii(":") + tr("Face") + QString::number(faceId) :
tr("No face selected"));
ui->pocketLength->blockSignals(false);
ui->spinOffset->blockSignals(false);
ui->lineFaceName->blockSignals(false);
ui->changeMode->blockSignals(false);
}
}
void TaskPocketParameters::apply()
{
std::string name = vp->getObject()->getNameInDocument();
//Gui::Command::openCommand("Pocket changed");
ui->pocketLength->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u",name.c_str(),getMode());
QString facename = getFaceName();
if (!facename.isEmpty()) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s",
name.c_str(), facename.toLatin1().data() );
} else
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = None", name.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i", name.c_str(), getReversed()?1:0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Offset = %f", name.c_str(), getOffset());
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgPocketParameters::TaskDlgPocketParameters(ViewProviderPocket *PocketView)
: TaskDlgSketchBasedParameters(PocketView)
{
assert(vp);
parameter = new TaskPocketParameters(static_cast<ViewProviderPocket*>(vp));
Content.push_back(parameter);
}
TaskDlgPocketParameters::~TaskDlgPocketParameters()
{
}
//==== calls from the TaskView ===============================================================
bool TaskDlgPocketParameters::accept()
{
<<<<<<< b551f892abed242e90afa77240bbdd7dcf7fc45c
try {
parameter->apply();
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
}
=======
parameter->apply();
>>>>>>> PartDesignGui: Make DressUp and SketchSupport propertie dialogs use common accept() structure
return TaskDlgSketchBasedParameters::accept();
}
#include "moc_TaskPocketParameters.cpp"

View File

@ -1,119 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskPocketParameters_H
#define GUI_TASKVIEW_TaskPocketParameters_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h>
#include "TaskSketchBasedParameters.h"
#include "ViewProviderPocket.h"
class Ui_TaskPocketParameters;
namespace App {
class Property;
}
namespace Gui {
class ViewProvider;
}
namespace PartDesignGui {
class TaskPocketParameters : public TaskSketchBasedParameters
{
Q_OBJECT
public:
TaskPocketParameters(ViewProviderPocket *PocketView,QWidget *parent = 0);
~TaskPocketParameters();
bool getReversed(void) const;
QByteArray getFaceName(void) const;
const bool updateView() const;
void apply();
private Q_SLOTS:
void onLengthChanged(double);
void onMidplaneChanged(bool);
void onReversedChanged(bool);
void onModeChanged(int);
void onButtonFace(const bool pressed = true);
void onFaceName(const QString& text);
protected:
void changeEvent(QEvent *e);
private:
double getLength(void) const;
bool getMidplane(void) const;
int getMode(void) const;
void onSelectionChanged(const Gui::SelectionChanges& msg);
void updateUI(int index);
private:
QWidget* proxy;
Ui_TaskPocketParameters* ui;
double oldLength;
};
/// simulation dialog for the TaskView
class TaskDlgPocketParameters : public TaskDlgSketchBasedParameters
{
Q_OBJECT
public:
TaskDlgPocketParameters(ViewProviderPocket *PocketView);
~TaskDlgPocketParameters();
ViewProviderPocket* getPocketView() const
{ return static_cast<ViewProviderPocket*>(vp); }
public:
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
<<<<<<< 0973b40e8e489ddbf6455e9a2e80b0520f143b58
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
=======
>>>>>>> Refactored code of SketchBased features to have common code in an abstract superclass
protected:
TaskPocketParameters *parameter;
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TASKAPPERANCE_H

View File

@ -1,435 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QMessageBox>
# include <QTimer>
#endif
#include "ui_TaskPolarPatternParameters.h"
#include "TaskPolarPatternParameters.h"
#include "TaskMultiTransformParameters.h"
#include "Workbench.h"
#include "ReferenceSelection.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/Part.h>
#include <App/Line.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/ViewProviderOrigin.h>
#include <Mod/PartDesign/App/FeaturePolarPattern.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/DatumLine.h>
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskPolarPatternParameters */
TaskPolarPatternParameters::TaskPolarPatternParameters(ViewProviderTransformed *TransformedView,QWidget *parent)
: TaskTransformedParameters(TransformedView, parent)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskPolarPatternParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true);
selectionMode = none;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
TaskPolarPatternParameters::TaskPolarPatternParameters(TaskMultiTransformParameters *parentTask, QLayout *layout)
: TaskTransformedParameters(parentTask)
{
proxy = new QWidget(parentTask);
ui = new Ui_TaskPolarPatternParameters();
ui->setupUi(proxy);
connect(ui->buttonOK, SIGNAL(pressed()),
parentTask, SLOT(onSubTaskButtonOK()));
QMetaObject::connectSlotsByName(this);
layout->addWidget(proxy);
ui->buttonOK->setEnabled(true);
ui->buttonAddFeature->hide();
ui->buttonRemoveFeature->hide();
ui->listWidgetFeatures->hide();
ui->checkBoxUpdateView->hide();
selectionMode = none;
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
void TaskPolarPatternParameters::setupUI()
{
connect(ui->buttonAddFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonAddFeature(bool)));
connect(ui->buttonRemoveFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonRemoveFeature(bool)));
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetFeatures->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onFeatureDeleted()));
ui->listWidgetFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
updateViewTimer = new QTimer(this);
updateViewTimer->setSingleShot(true);
updateViewTimer->setInterval(getUpdateViewTimeout());
connect(updateViewTimer, SIGNAL(timeout()),
this, SLOT(onUpdateViewTimer()));
connect(ui->comboAxis, SIGNAL(activated(int)),
this, SLOT(onAxisChanged(int)));
connect(ui->checkReverse, SIGNAL(toggled(bool)),
this, SLOT(onCheckReverse(bool)));
connect(ui->polarAngle, SIGNAL(valueChanged(double)),
this, SLOT(onAngle(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(uint)),
this, SLOT(onOccurrences(uint)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
// Get the feature data
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
std::vector<App::DocumentObject*> originals = pcPolarPattern->Originals.getValues();
// Fill data into dialog elements
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); ++i)
{
if ((*i) != NULL)
ui->listWidgetFeatures->addItem(QString::fromLatin1((*i)->getNameInDocument()));
}
// ---------------------
ui->polarAngle->bind(pcPolarPattern->Angle);
ui->spinOccurrences->setMaximum(INT_MAX);
ui->spinOccurrences->bind(pcPolarPattern->Occurrences);
ui->comboAxis->setEnabled(true);
ui->checkReverse->setEnabled(true);
ui->polarAngle->setEnabled(true);
ui->spinOccurrences->setEnabled(true);
App::DocumentObject* sketch = getSketchObject();
if (!(sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId())))
sketch = 0;
this->axesLinks.setCombo(*(ui->comboAxis));
this->fillAxisCombo(axesLinks, static_cast<Part::Part2DObject*>(sketch));
updateUI();
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument());
origin->setTemporaryVisibilityAxis(true);
}
}
}
void TaskPolarPatternParameters::updateUI()
{
if (blockUpdate)
return;
blockUpdate = true;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
bool reverse = pcPolarPattern->Reversed.getValue();
double angle = pcPolarPattern->Angle.getValue();
unsigned occurrences = pcPolarPattern->Occurrences.getValue();
if (axesLinks.setCurrentLink(pcPolarPattern->Axis) == -1){
//failed to set current, because the link isnt in the list yet
axesLinks.addLink(pcPolarPattern->Axis, getRefStr(pcPolarPattern->Axis.getValue(),pcPolarPattern->Axis.getSubValues()));
axesLinks.setCurrentLink(pcPolarPattern->Axis);
}
// Note: These three lines would trigger onLength(), on Occurrences() and another updateUI() if we
// didn't check for blockUpdate
ui->checkReverse->setChecked(reverse);
ui->polarAngle->setValue(angle);
ui->spinOccurrences->setValue(occurrences);
blockUpdate = false;
}
void TaskPolarPatternParameters::onUpdateViewTimer()
{
recomputeFeature();
}
void TaskPolarPatternParameters::kickUpdateViewTimer() const
{
updateViewTimer->start();
}
void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
if (originalSelected(msg)) {
if (selectionMode == addFeature)
ui->listWidgetFeatures->addItem(QString::fromLatin1(msg.pObjectName));
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
exitSelectionMode();
std::vector<std::string> axes;
App::DocumentObject* selObj;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
getReferencedSelection(pcPolarPattern, msg, selObj, axes);
pcPolarPattern->Axis.setValue(selObj, axes);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) {
std::vector<std::string> axes;
App::DocumentObject* selObj;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
getReferencedSelection(pcPolarPattern, msg, selObj, axes);
pcPolarPattern->Axis.setValue(selObj, axes);
recomputeFeature();
updateUI();
}
}
}
void TaskPolarPatternParameters::clearButtons()
{
ui->buttonAddFeature->setChecked(false);
ui->buttonRemoveFeature->setChecked(false);
}
void TaskPolarPatternParameters::onCheckReverse(const bool on) {
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Reversed.setValue(on);
exitSelectionMode();
kickUpdateViewTimer();
}
void TaskPolarPatternParameters::onAngle(const double a) {
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Angle.setValue(a);
exitSelectionMode();
kickUpdateViewTimer();
}
void TaskPolarPatternParameters::onOccurrences(const uint n) {
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
pcPolarPattern->Occurrences.setValue(n);
exitSelectionMode();
kickUpdateViewTimer();
}
void TaskPolarPatternParameters::onAxisChanged(int num) {
if (blockUpdate)
return;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
try{
if(axesLinks.getCurrentLink().getValue() == 0){
// enter reference selection mode
hideObject();
showBase();
selectionMode = reference;
Gui::Selection().clearSelection();
addReferenceSelectionGate(true, false);
} else {
exitSelectionMode();
pcPolarPattern->Axis.Paste(axesLinks.getCurrentLink());
}
} catch (Base::Exception &e) {
QMessageBox::warning(0,tr("Error"),QString::fromAscii(e.what()));
}
kickUpdateViewTimer();
}
void TaskPolarPatternParameters::onUpdateView(bool on)
{
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgPolarPatternParameters::accept() but without doCommand
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
std::vector<std::string> axes;
App::DocumentObject* obj;
getAxis(obj, axes);
pcPolarPattern->Axis.setValue(obj,axes);
pcPolarPattern->Reversed.setValue(getReverse());
pcPolarPattern->Angle.setValue(getAngle());
pcPolarPattern->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
}
void TaskPolarPatternParameters::onFeatureDeleted(void)
{
PartDesign::Transformed* pcTransformed = getObject();
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
originals.erase(originals.begin() + ui->listWidgetFeatures->currentRow());
pcTransformed->Originals.setValues(originals);
ui->listWidgetFeatures->model()->removeRow(ui->listWidgetFeatures->currentRow());
recomputeFeature();
}
void TaskPolarPatternParameters::getAxis(App::DocumentObject*& obj, std::vector<std::string>& sub) const
{
const App::PropertyLinkSub &lnk = axesLinks.getCurrentLink();
obj = lnk.getValue();
sub = lnk.getSubValues();
}
const bool TaskPolarPatternParameters::getReverse(void) const
{
return ui->checkReverse->isChecked();
}
const double TaskPolarPatternParameters::getAngle(void) const
{
return ui->polarAngle->value().getValue();
}
const unsigned TaskPolarPatternParameters::getOccurrences(void) const
{
return ui->spinOccurrences->value();
}
TaskPolarPatternParameters::~TaskPolarPatternParameters()
{
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->setTemporaryVisibilityMode(false);
}
}
delete ui;
if (proxy)
delete proxy;
}
void TaskPolarPatternParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
void TaskPolarPatternParameters::apply()
{
std::string name = TransformedView->getObject()->getNameInDocument();
std::vector<std::string> axes;
App::DocumentObject* obj;
getAxis(obj, axes);
std::string axis = getPythonStr(obj, axes);
if (!axis.empty() && obj) {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = %s", name.c_str(), axis.c_str());
} else {
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Axis = None", name.c_str());
}
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),getReverse());
ui->polarAngle->apply();
ui->spinOccurrences->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgPolarPatternParameters::TaskDlgPolarPatternParameters(ViewProviderPolarPattern *PolarPatternView)
: TaskDlgTransformedParameters(PolarPatternView)
{
parameter = new TaskPolarPatternParameters(PolarPatternView);
Content.push_back(parameter);
}
//==== calls from the TaskView ===============================================================
bool TaskDlgPolarPatternParameters::accept()
{
parameter->apply();
<<<<<<< a6aea83ec9ef83d52a06178b32175b3e79f73c65
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
}
=======
>>>>>>> PartDesign: make transform parameter dialogs use common base code with other dialogs
return TaskDlgTransformedParameters::accept();
}
#include "moc_TaskPolarPatternParameters.cpp"

View File

@ -1,410 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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"
#ifndef _PreComp_
#endif
#include "ui_TaskRevolutionParameters.h"
#include "TaskRevolutionParameters.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/DatumLine.h>
#include <Mod/PartDesign/App/FeatureRevolution.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/Body.h>
#include "ReferenceSelection.h"
#include "TaskSketchBasedParameters.h"
#include "Workbench.h"
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskRevolutionParameters */
TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent)
: TaskSketchBasedParameters(RevolutionView, parent, "PartDesign_Revolution",tr("Revolution parameters"))
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskRevolutionParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
connect(ui->revolveAngle, SIGNAL(valueChanged(double)),
this, SLOT(onAngleChanged(double)));
connect(ui->axis, SIGNAL(activated(int)),
this, SLOT(onAxisChanged(int)));
connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)),
this, SLOT(onMidplane(bool)));
connect(ui->checkBoxReversed, SIGNAL(toggled(bool)),
this, SLOT(onReversed(bool)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
this->groupLayout()->addWidget(proxy);
// Temporarily prevent unnecessary feature recomputes
ui->revolveAngle->blockSignals(true);
ui->axis->blockSignals(true);
ui->checkBoxMidplane->blockSignals(true);
ui->checkBoxReversed->blockSignals(true);
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
double l = pcRevolution->Angle.getValue();
bool mirrored = pcRevolution->Midplane.getValue();
bool reversed = pcRevolution->Reversed.getValue();
ui->revolveAngle->setValue(l);
<<<<<<< f0798a82fe8f03db57aca4f634d2123486daaea0
int count=pcRevolution->getSketchAxisCount();
for (int i=ui->axis->count()-1; i >= count+2; i--)
ui->axis->removeItem(i);
for (int i=ui->axis->count(); i < count+2; i++)
ui->axis->addItem(QString::fromLatin1("Sketch axis %1").arg(i-2));
int pos=-1;
App::DocumentObject *pcReferenceAxis = pcRevolution->ReferenceAxis.getValue();
const std::vector<std::string> &subReferenceAxis = pcRevolution->ReferenceAxis.getSubValues();
if (pcReferenceAxis && pcReferenceAxis == pcRevolution->Sketch.getValue()) {
assert(subReferenceAxis.size()==1);
if (subReferenceAxis[0] == "V_Axis")
pos = 0;
else if (subReferenceAxis[0] == "H_Axis")
pos = 1;
else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis")
pos = 2 + std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
}
if (pos < 0 || pos >= ui->axis->count()) {
ui->axis->addItem(tr("Undefined"));
pos = ui->axis->count()-1;
}
ui->axis->setCurrentIndex(pos);
=======
blockUpdate = false;
updateUI();
>>>>>>> Enable edges and datum lines as rotation axis for Groove and Revolution features
ui->checkBoxMidplane->setChecked(mirrored);
ui->checkBoxReversed->setChecked(reversed);
ui->revolveAngle->bind(pcRevolution->Angle);
ui->doubleSpinBox->blockSignals(false);
ui->axis->blockSignals(false);
ui->checkBoxMidplane->blockSignals(false);
ui->checkBoxReversed->blockSignals(false);
setFocus ();
}
void TaskRevolutionParameters::updateUI()
{
if (blockUpdate)
return;
blockUpdate = true;
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
App::DocumentObject* pcReferenceAxis = pcRevolution->ReferenceAxis.getValue();
std::vector<std::string> sub = pcRevolution->ReferenceAxis.getSubValues();
// Add user-defined sketch axes to the reference selection combo box
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
int maxcount=2;
if (pcSketch)
maxcount += pcSketch->getAxisCount();
for (int i=ui->axis->count()-1; i >= 2; i--)
ui->axis->removeItem(i);
for (int i=ui->axis->count(); i < maxcount; i++)
ui->axis->addItem(QString::fromAscii("Sketch axis %1").arg(i-5));
bool undefined = false;
if (pcReferenceAxis != NULL && !sub.empty()) {
if (sub.front() == "H_Axis")
ui->axis->setCurrentIndex(0);
else if (sub.front() == "V_Axis")
ui->axis->setCurrentIndex(1);
else if (sub.front().size() > 4 && sub.front().substr(0,4) == "Axis") {
int pos = 2 + std::atoi(sub.front().substr(4,4000).c_str());
if (pos <= maxcount)
ui->axis->setCurrentIndex(pos);
else
undefined = true;
} else {
ui->axis->addItem(getRefStr(pcReferenceAxis, sub));
ui->axis->setCurrentIndex(maxcount);
}
} else {
undefined = true;
}
ui->axis->addItem(tr("Select reference..."));
blockUpdate = false;
}
void TaskRevolutionParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
exitSelectionMode();
if (!blockUpdate) {
std::vector<std::string> axis;
App::DocumentObject* selObj;
getReferencedSelection(pcRevolution, msg, selObj, axis);
pcRevolution->ReferenceAxis.setValue(selObj, axis);
recomputeFeature();
updateUI();
}
else {
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
int maxcount=2;
if (pcSketch)
maxcount += pcSketch->getAxisCount();
for (int i=ui->axis->count()-1; i >= maxcount; i--)
ui->axis->removeItem(i);
std::vector<std::string> sub;
App::DocumentObject* selObj;
getReferencedSelection(pcRevolution, msg, selObj, sub);
ui->axis->addItem(getRefStr(selObj, sub));
ui->axis->setCurrentIndex(maxcount);
ui->axis->addItem(tr("Select reference..."));
}
}
}
void TaskRevolutionParameters::onAngleChanged(double len)
{
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
pcRevolution->Angle.setValue(len);
exitSelectionMode();
recomputeFeature();
}
void TaskRevolutionParameters::onAxisChanged(int num)
{
if (blockUpdate)
return;
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
Sketcher::SketchObject *pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
if (pcSketch) {
App::DocumentObject *oldRefAxis = pcRevolution->ReferenceAxis.getValue();
std::vector<std::string> oldSubRefAxis = pcRevolution->ReferenceAxis.getSubValues();
int maxcount = pcSketch->getAxisCount()+2;
if (num == 0) {
pcRevolution->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"H_Axis"));
exitSelectionMode();
} else if (num == 1) {
pcRevolution->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,"V_Axis"));
exitSelectionMode();
} else if (num >= 2 && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-2);
std::string str = buf.toStdString();
pcRevolution->ReferenceAxis.setValue(pcSketch, std::vector<std::string>(1,str));
exitSelectionMode();
} else if (num == ui->axis->count() - 1) {
// enter reference selection mode
TaskSketchBasedParameters::onSelectReference(true, true, false, true);
} else if (num == maxcount)
exitSelectionMode();
App::DocumentObject *newRefAxis = pcRevolution->ReferenceAxis.getValue();
const std::vector<std::string> &newSubRefAxis = pcRevolution->ReferenceAxis.getSubValues();
if (oldRefAxis != newRefAxis ||
oldSubRefAxis.size() != newSubRefAxis.size() ||
oldSubRefAxis[0] != newSubRefAxis[0]) {
bool reversed = pcRevolution->suggestReversed();
if (reversed != pcRevolution->Reversed.getValue()) {
pcRevolution->Reversed.setValue(reversed);
ui->checkBoxReversed->blockSignals(true);
ui->checkBoxReversed->setChecked(reversed);
ui->checkBoxReversed->blockSignals(false);
}
}
}
updateUI();
recomputeFeature();
}
void TaskRevolutionParameters::onMidplane(bool on)
{
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
pcRevolution->Midplane.setValue(on);
recomputeFeature();
}
void TaskRevolutionParameters::onReversed(bool on)
{
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
pcRevolution->Reversed.setValue(on);
recomputeFeature();
}
double TaskRevolutionParameters::getAngle(void) const
{
return ui->revolveAngle->value().getValue();
}
void TaskRevolutionParameters::getReferenceAxis(App::DocumentObject*& obj, std::vector<std::string>& sub) const
{
// get the support and Sketch
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(vp->getObject());
obj = static_cast<Sketcher::SketchObject*>(pcRevolution->Sketch.getValue());
sub = std::vector<std::string>(1,"");
int maxcount=2;
if (obj)
maxcount += static_cast<Part::Part2DObject*>(obj)->getAxisCount();
if (obj) {
int num = ui->axis->currentIndex();
if (num == 0)
sub[0] = "H_Axis";
else if (num == 1)
sub[0] = "V_Axis";
else if (num >= 2 && num < maxcount) {
QString buf = QString::fromUtf8("Axis%1").arg(num-2);
sub[0] = buf.toStdString();
} else if (num == maxcount && ui->axis->count() == maxcount + 2) {
QStringList parts = ui->axis->currentText().split(QChar::fromAscii(':'));
obj = vp->getObject()->getDocument()->getObject(parts[0].toStdString().c_str());
if (parts.size() > 1)
sub[0] = parts[1].toStdString();
} else {
obj = NULL;
}
}
else
obj = NULL;
}
bool TaskRevolutionParameters::getMidplane(void) const
{
return ui->checkBoxMidplane->isChecked();
}
bool TaskRevolutionParameters::getReversed(void) const
{
return ui->checkBoxReversed->isChecked();
}
TaskRevolutionParameters::~TaskRevolutionParameters()
{
delete ui;
}
void TaskRevolutionParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
void TaskRevolutionParameters::apply()
{
App::DocumentObject* revolve = vp->getObject();
std::string name = revolve->getNameInDocument();
// retrieve sketch and its support object
App::DocumentObject* sketch = 0;
App::DocumentObject* support = 0;
if (revolve->getTypeId().isDerivedFrom(PartDesign::Revolution::getClassTypeId())) {
sketch = static_cast<PartDesign::Revolution*>(revolve)->Sketch.getValue<Sketcher::SketchObject*>();
if (sketch) {
support = static_cast<Sketcher::SketchObject*>(sketch)->Support.getValue();
}
}
//Gui::Command::openCommand("Revolution changed");
ui->revolveAngle->apply();
std::vector<std::string> sub;
App::DocumentObject* obj;
parameter->getReferenceAxis(obj, sub);
std::string axis = getPythonStr(obj, sub);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.ReferenceAxis = %s",name.c_str(),axis.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(), getMidplane() ? 1 : 0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(), getReversed() ? 1 : 0);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (revolve->isValid()) {
if (sketch)
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
if (support)
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
}
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgRevolutionParameters::TaskDlgRevolutionParameters(ViewProviderRevolution *RevolutionView)
: TaskDlgSketchBasedParameters(RevolutionView)
{
assert(RevolutionView);
parameter = new TaskRevolutionParameters(RevolutionView);
Content.push_back(parameter);
}
TaskDlgRevolutionParameters::~TaskDlgRevolutionParameters()
{
}
//==== calls from the TaskView ===============================================================
bool TaskDlgRevolutionParameters::accept()
{
parameter->apply();
return true;
}
#include "moc_TaskRevolutionParameters.cpp"

View File

@ -1,111 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* *
* 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 *
* *
***************************************************************************/
#ifndef GUI_TASKVIEW_TaskRevolutionParameters_H
#define GUI_TASKVIEW_TaskRevolutionParameters_H
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include <Gui/TaskView/TaskDialog.h>
#include "TaskSketchBasedParameters.h"
#include "ViewProviderRevolution.h"
class Ui_TaskRevolutionParameters;
namespace App {
class Property;
}
namespace Gui {
class ViewProvider;
}
namespace PartDesignGui {
class TaskRevolutionParameters : public TaskSketchBasedParameters
{
Q_OBJECT
public:
TaskRevolutionParameters(ViewProviderRevolution *RevolutionView,QWidget *parent = 0);
~TaskRevolutionParameters();
void apply();
private Q_SLOTS:
void onAngleChanged(double);
void onAxisChanged(int);
void onMidplane(bool);
void onReversed(bool);
protected:
void onSelectionChanged(const Gui::SelectionChanges& msg) {}
void changeEvent(QEvent *e);
const bool updateView() const;
QString getReferenceAxis(void) const;
double getAngle(void) const;
bool getMidplane(void) const;
bool getReversed(void) const;
private:
QWidget* proxy;
Ui_TaskRevolutionParameters* ui;
};
/// simulation dialog for the TaskView
class TaskDlgRevolutionParameters : public TaskDlgSketchBasedParameters
{
Q_OBJECT
public:
TaskDlgRevolutionParameters(ViewProviderRevolution *RevolutionView);
~TaskDlgRevolutionParameters();
ViewProviderRevolution* getRevolutionView() const
{ return static_cast<ViewProviderRevolution*>(vp); }
public:
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
<<<<<<< 0973b40e8e489ddbf6455e9a2e80b0520f143b58
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
=======
>>>>>>> Refactored code of SketchBased features to have common code in an abstract superclass
protected:
TaskRevolutionParameters *parameter;
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TASKAPPERANCE_H

View File

@ -1,273 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QMessageBox>
#endif
#include "ui_TaskScaledParameters.h"
#include "TaskScaledParameters.h"
#include "TaskMultiTransformParameters.h"
#include <Base/UnitsApi.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureScaled.h>
#include <Mod/Sketcher/App/SketchObject.h>
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskScaledParameters */
TaskScaledParameters::TaskScaledParameters(ViewProviderTransformed *TransformedView,QWidget *parent)
: TaskTransformedParameters(TransformedView, parent)
{
// we need a separate container widget to add all controls to
proxy = new QWidget(this);
ui = new Ui_TaskScaledParameters();
ui->setupUi(proxy);
QMetaObject::connectSlotsByName(this);
this->groupLayout()->addWidget(proxy);
ui->buttonOK->hide();
ui->checkBoxUpdateView->setEnabled(true);
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
TaskScaledParameters::TaskScaledParameters(TaskMultiTransformParameters *parentTask, QLayout *layout)
: TaskTransformedParameters(parentTask)
{
proxy = new QWidget(parentTask);
ui = new Ui_TaskScaledParameters();
ui->setupUi(proxy);
connect(ui->buttonOK, SIGNAL(pressed()),
parentTask, SLOT(onSubTaskButtonOK()));
QMetaObject::connectSlotsByName(this);
layout->addWidget(proxy);
ui->buttonOK->setEnabled(true);
ui->buttonAddFeature->hide();
ui->buttonRemoveFeature->hide();
ui->listWidgetFeatures->hide();
ui->checkBoxUpdateView->hide();
blockUpdate = false; // Hack, sometimes it is NOT false although set to false in Transformed::Transformed()!!
setupUI();
}
void TaskScaledParameters::setupUI()
{
connect(ui->buttonAddFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonAddFeature(bool)));
connect(ui->buttonRemoveFeature, SIGNAL(toggled(bool)), this, SLOT(onButtonRemoveFeature(bool)));
// Create context menu
QAction* action = new QAction(tr("Remove"), this);
ui->listWidgetFeatures->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onFeatureDeleted()));
ui->listWidgetFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(ui->spinFactor, SIGNAL(valueChanged(double)),
this, SLOT(onFactor(double)));
connect(ui->spinOccurrences, SIGNAL(valueChanged(uint)),
this, SLOT(onOccurrences(uint)));
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
// Get the feature data
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
std::vector<App::DocumentObject*> originals = pcScaled->Originals.getValues();
// Fill data into dialog elements
for (std::vector<App::DocumentObject*>::const_iterator i = originals.begin(); i != originals.end(); ++i)
{
if ((*i) != NULL)
ui->listWidgetFeatures->addItem(QString::fromLatin1((*i)->getNameInDocument()));
}
// ---------------------
ui->spinFactor->bind(pcScaled->Factor);
ui->spinOccurrences->setMaximum(INT_MAX);
ui->spinOccurrences->bind(pcScaled->Occurrences);
ui->spinFactor->setEnabled(true);
ui->spinOccurrences->setEnabled(true);
//ui->spinFactor->setDecimals(Base::UnitsApi::getDecimals());
updateUI();
}
void TaskScaledParameters::updateUI()
{
if (blockUpdate)
return;
blockUpdate = true;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
double factor = pcScaled->Factor.getValue();
unsigned occurrences = pcScaled->Occurrences.getValue();
ui->spinFactor->setValue(factor);
ui->spinOccurrences->setValue(occurrences);
blockUpdate = false;
}
void TaskScaledParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (originalSelected(msg)) {
if (selectionMode == addFeature)
ui->listWidgetFeatures->addItem(QString::fromLatin1(msg.pObjectName));
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
}
}
void TaskScaledParameters::clearButtons()
{
ui->buttonAddFeature->setChecked(false);
ui->buttonRemoveFeature->setChecked(false);
}
void TaskScaledParameters::onFactor(const double f)
{
if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Factor.setValue(f);
recomputeFeature();
}
void TaskScaledParameters::onOccurrences(const uint n)
{
if (blockUpdate)
return;
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Occurrences.setValue(n);
recomputeFeature();
}
void TaskScaledParameters::onUpdateView(bool on)
{
blockUpdate = !on;
if (on) {
// Do the same like in TaskDlgScaledParameters::accept() but without doCommand
PartDesign::Scaled* pcScaled = static_cast<PartDesign::Scaled*>(getObject());
pcScaled->Factor.setValue(getFactor());
pcScaled->Occurrences.setValue(getOccurrences());
recomputeFeature();
}
}
void TaskScaledParameters::onFeatureDeleted(void)
{
PartDesign::Transformed* pcTransformed = getObject();
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
originals.erase(originals.begin() + ui->listWidgetFeatures->currentRow());
pcTransformed->Originals.setValues(originals);
ui->listWidgetFeatures->model()->removeRow(ui->listWidgetFeatures->currentRow());
recomputeFeature();
}
const double TaskScaledParameters::getFactor(void) const
{
return ui->spinFactor->value().getValue();
}
const unsigned TaskScaledParameters::getOccurrences(void) const
{
return ui->spinOccurrences->value();
}
TaskScaledParameters::~TaskScaledParameters()
{
delete ui;
if (proxy)
delete proxy;
}
void TaskScaledParameters::changeEvent(QEvent *e)
{
TaskBox::changeEvent(e);
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(proxy);
}
}
void TaskScaledParameters::apply()
{
std::string name = TransformedView->getObject()->getNameInDocument();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Factor = %f",name.c_str(), getFactor());
ui->spinOccurrences->apply();
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
if (!TransformedView->getObject()->isValid())
throw Base::Exception(TransformedView->getObject()->getStatusString());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand();
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgScaledParameters::TaskDlgScaledParameters(ViewProviderScaled *ScaledView)
: TaskDlgTransformedParameters(ScaledView)
{
parameter = new TaskScaledParameters(ScaledView);
Content.push_back(parameter);
}
//==== calls from the TaskView ===============================================================
bool TaskDlgScaledParameters::accept()
{
parameter->apply();
<<<<<<< a6aea83ec9ef83d52a06178b32175b3e79f73c65
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
}
=======
>>>>>>> PartDesign: make transform parameter dialogs use common base code with other dialogs
return TaskDlgTransformedParameters::accept();
}
#include "moc_TaskScaledParameters.cpp"

View File

@ -1,519 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <QMessageBox>
# include <QListWidget>
# include <TopoDS_Shape.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS.hxx>
# include <BRepAdaptor_Surface.hxx>
#endif
#include "TaskTransformedParameters.h"
#include "TaskMultiTransformParameters.h"
#include "Workbench.h"
#include <App/Application.h>
#include <App/Document.h>
#include <App/Part.h>
#include <App/Origin.h>
#include <App/Plane.h>
#include <App/Line.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Mod/PartDesign/App/FeatureTransformed.h>
#include <Mod/PartDesign/App/Body.h>
#include <Mod/PartDesign/App/FeatureAddSub.h>
#include "ReferenceSelection.h"
using namespace PartDesignGui;
using namespace Gui;
/* TRANSLATOR PartDesignGui::TaskTransformedParameters */
TaskTransformedParameters::TaskTransformedParameters(ViewProviderTransformed *TransformedView, QWidget *parent)
: TaskBox(Gui::BitmapFactory().pixmap((std::string("PartDesign_") + TransformedView->featureName).c_str()),
QString::fromLatin1((TransformedView->featureName + " parameters").c_str()),
true,
parent),
TransformedView(TransformedView),
parentTask(NULL),
insideMultiTransform(false),
blockUpdate(false)
{
selectionMode = none;
}
TaskTransformedParameters::TaskTransformedParameters(TaskMultiTransformParameters *parentTask)
: TaskBox(QPixmap(), tr(""), true, parentTask),
TransformedView(NULL),
parentTask(parentTask),
insideMultiTransform(true),
blockUpdate(false)
{
// Original feature selection makes no sense inside a MultiTransform
selectionMode = none;
}
TaskTransformedParameters::~TaskTransformedParameters()
{
// make sure to remove selection gate in all cases
Gui::Selection().rmvSelectionGate();
}
bool TaskTransformedParameters::isViewUpdated() const
{
return (blockUpdate == false);
}
int TaskTransformedParameters::getUpdateViewTimeout() const
{
return 500;
}
const bool TaskTransformedParameters::originalSelected(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection && (
(selectionMode == addFeature) || (selectionMode == removeFeature))) {
if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0)
return false;
PartDesign::Transformed* pcTransformed = getObject();
App::DocumentObject* selectedObject = pcTransformed->getDocument()->getObject(msg.pObjectName);
if (selectedObject->isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) {
// Do the same like in TaskDlgTransformedParameters::accept() but without doCommand
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
std::vector<App::DocumentObject*>::iterator o = std::find(originals.begin(), originals.end(), selectedObject);
if (selectionMode == addFeature) {
if (o == originals.end())
originals.push_back(selectedObject);
else
return false; // duplicate selection
} else {
if (o != originals.end())
originals.erase(o);
else
return false;
}
pcTransformed->Originals.setValues(originals);
recomputeFeature();
return true;
}
}
return false;
}
void TaskTransformedParameters::onButtonAddFeature(bool checked)
{
if (checked) {
hideObject();
showBase();
selectionMode = addFeature;
Gui::Selection().clearSelection();
} else {
exitSelectionMode();
}
}
void TaskTransformedParameters::onButtonRemoveFeature(bool checked)
{
if (checked) {
hideObject();
showBase();
selectionMode = removeFeature;
Gui::Selection().clearSelection();
} else {
exitSelectionMode();
}
}
void TaskTransformedParameters::removeItemFromListWidget(QListWidget* widget, const char* itemstr)
{
QList<QListWidgetItem*> items = widget->findItems(QString::fromAscii(itemstr), Qt::MatchExactly);
if (!items.empty()) {
for (QList<QListWidgetItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
QListWidgetItem* it = widget->takeItem(widget->row(*i));
delete it;
}
}
}
App::DocumentObject* TaskTransformedParameters::getPartPlanes(const char* str) const {
//TODO: Adjust to GRAPH handling when available
App::DocumentObject* obj = getObject();
App::Part* part = getPartFor(obj, false);
if (part) {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
if(origs.size()<1)
return nullptr;
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
auto planes = orig->getObjectsOfType(App::Plane::getClassTypeId());
for(App::DocumentObject* plane : planes) {
if( strcmp(static_cast<App::Plane*>(plane)->PlaneType.getValue(), str) == 0)
return plane;
}
}
return nullptr;
}
App::DocumentObject* TaskTransformedParameters::getPartLines(const char* str) const {
//TODO: Adjust to GRAPH handling when available
App::DocumentObject* obj = getObject();
App::Part* part = getPartFor(obj, false);
if (part) {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
if(origs.size()<1)
return nullptr;
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
auto lines = orig->getObjectsOfType(App::Line::getClassTypeId());
for(App::DocumentObject* line : lines) {
if( strcmp(static_cast<App::Line*>(line)->LineType.getValue(), str) == 0)
return line;
}
}
return nullptr;
}
void TaskTransformedParameters::fillAxisCombo(ComboLinks &combolinks,
Part::Part2DObject* sketch)
{
combolinks.clear();
//add sketch axes
if (sketch){
combolinks.addLink(sketch, "N_Axis",tr("Normal sketch axis"));
combolinks.addLink(sketch,"V_Axis",tr("Vertical sketch axis"));
combolinks.addLink(sketch,"H_Axis",tr("Horizontal sketch axis"));
for (int i=0; i < sketch->getAxisCount(); i++) {
QString itemText = tr("Construction line %1").arg(i+1);
std::stringstream sub;
sub << "Axis" << i;
combolinks.addLink(sketch,sub.str(),itemText);
}
}
//add part axes
App::DocumentObject* line = 0;
line = getPartLines(App::Part::BaselineTypes[0]);
if(line)
combolinks.addLink(line,"",tr("Base X axis"));
line = getPartLines(App::Part::BaselineTypes[1]);
if(line)
combolinks.addLink(line,"",tr("Base Y axis"));
line = getPartLines(App::Part::BaselineTypes[2]);
if(line)
combolinks.addLink(line,"",tr("Base Z axis"));
//add "Select reference"
combolinks.addLink(0,std::string(),tr("Select reference..."));
}
void TaskTransformedParameters::fillPlanesCombo(ComboLinks &combolinks,
Part::Part2DObject* sketch)
{
combolinks.clear();
//add sketch axes
if (sketch){
combolinks.addLink(sketch,"V_Axis",QObject::tr("Vertical sketch axis"));
combolinks.addLink(sketch,"H_Axis",QObject::tr("Horizontal sketch axis"));
for (int i=0; i < sketch->getAxisCount(); i++) {
QString itemText = tr("Construction line %1").arg(i+1);
std::stringstream sub;
sub << "Axis" << i;
combolinks.addLink(sketch,sub.str(),itemText);
}
}
//add part baseplanes
App::DocumentObject* plane = 0;
plane = getPartPlanes(App::Part::BaseplaneTypes[0]);
if(plane)
combolinks.addLink(plane,"",tr("Base XY plane"));
plane = getPartPlanes(App::Part::BaseplaneTypes[1]);
if(plane)
combolinks.addLink(plane,"",tr("Base XZ plane"));
plane = getPartPlanes(App::Part::BaseplaneTypes[2]);
if(plane)
combolinks.addLink(plane,"",tr("Base YZ plane"));
//add "Select reference"
combolinks.addLink(0,std::string(),tr("Select reference..."));
}
void TaskTransformedParameters::recomputeFeature() {
getTopTransformedView()->recomputeFeature();
}
PartDesignGui::ViewProviderTransformed *TaskTransformedParameters::getTopTransformedView() const {
PartDesignGui::ViewProviderTransformed *rv;
if (insideMultiTransform) {
rv = parentTask->TransformedView;
} else {
rv = TransformedView;
}
assert (rv);
return rv;
}
PartDesign::Transformed *TaskTransformedParameters::getTopTransformedObject() const {
App::DocumentObject *transform = getTopTransformedView()->getObject();
assert (transform->isDerivedFrom(PartDesign::Transformed::getClassTypeId()));
return static_cast<PartDesign::Transformed*>(transform);
}
PartDesign::Transformed *TaskTransformedParameters::getObject() const {
if (insideMultiTransform)
return parentTask->getSubFeature();
else
return static_cast<PartDesign::Transformed*>(TransformedView->getObject());
}
Part::Feature *TaskTransformedParameters::getBaseObject() const {
PartDesign::Feature* feature = getTopTransformedObject ();
// NOTE: getBaseObject() throws if there is no base; shouldn't happen here.
return feature->getBaseObject();
}
const std::vector<App::DocumentObject*> & TaskTransformedParameters::getOriginals(void) const {
return getTopTransformedObject()->Originals.getValues();
}
App::DocumentObject* TaskTransformedParameters::getSketchObject() const {
return getTopTransformedObject()->getSketchObject();
}
void TaskTransformedParameters::hideObject()
{
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
doc->setHide(getTopTransformedObject()->getNameInDocument());
}
}
void TaskTransformedParameters::showObject()
{
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
doc->setShow(getTopTransformedObject()->getNameInDocument());
}
}
void TaskTransformedParameters::hideBase()
{
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
try {
doc->setHide(getBaseObject()->getNameInDocument());
} catch (const Base::Exception &) { }
}
}
void TaskTransformedParameters::showBase()
{
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
try {
doc->setShow(getBaseObject()->getNameInDocument());
} catch (const Base::Exception &) { }
}
}
void TaskTransformedParameters::exitSelectionMode()
{
clearButtons();
selectionMode = none;
Gui::Selection().rmvSelectionGate();
showObject();
hideBase();
}
void TaskTransformedParameters::addReferenceSelectionGate(bool edge, bool face)
{
Gui::Selection().addSelectionGate(new ReferenceSelection(getBaseObject(), edge, face, /*point =*/ true));
}
//**************************************************************************
//**************************************************************************
// TaskDialog
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TaskDlgTransformedParameters::TaskDlgTransformedParameters(ViewProviderTransformed *TransformedView_)
: TaskDlgFeatureParameters(TransformedView_)
{
assert(vp);
message = new TaskTransformedMessages(getTransformedView());
Content.push_back(message);
}
//==== calls from the TaskView ===============================================================
bool TaskDlgTransformedParameters::accept()
{
<<<<<<< a6aea83ec9ef83d52a06178b32175b3e79f73c65
std::string name = TransformedView->getObject()->getNameInDocument();
try {
//Gui::Command::openCommand(featureName + " changed");
std::vector<App::DocumentObject*> originals = parameter->getOriginals();
std::stringstream str;
str << "App.ActiveDocument." << name.c_str() << ".Originals = [";
for (std::vector<App::DocumentObject*>::const_iterator it = originals.begin(); it != originals.end(); ++it)
{
if ((*it) != NULL)
str << "App.ActiveDocument." << (*it)->getNameInDocument() << ",";
}
str << "]";
Gui::Command::runCommand(Gui::Command::Doc,str.str().c_str());
}
catch (const Base::Exception& e) {
QMessageBox::warning(parameter, tr("Input error"), QString::fromLatin1(e.what()));
return false;
=======
std::string name = vp->getObject()->getNameInDocument();
//Gui::Command::openCommand(featureName + " changed");
std::vector<App::DocumentObject*> originals = parameter->getOriginals();
std::stringstream str;
str << "App.ActiveDocument." << name.c_str() << ".Originals = [";
for (std::vector<App::DocumentObject*>::const_iterator it = originals.begin(); it != originals.end(); ++it)
{
if ((*it) != NULL)
str << "App.ActiveDocument." << (*it)->getNameInDocument() << ",";
>>>>>>> PartDesign: make transform parameter dialogs use common base code with other dialogs
}
str << "]";
Gui::Command::runCommand(Gui::Command::Doc,str.str().c_str());
// Continue (usually in virtual method accept())
return TaskDlgFeatureParameters::accept ();
}
bool TaskDlgTransformedParameters::reject()
{
// ensure that we are not in selection mode
parameter->exitSelectionMode();
return TaskDlgFeatureParameters::reject ();
}
#include "moc_TaskTransformedParameters.cpp"
ComboLinks::ComboLinks(QComboBox &combo)
: doc(0)
{
this->_combo = &combo;
_combo->clear();
}
int ComboLinks::addLink(const App::PropertyLinkSub &lnk, QString itemText)
{
if(!_combo)
return 0;
_combo->addItem(itemText);
this->linksInList.push_back(new App::PropertyLinkSub());
App::PropertyLinkSub &newitem = *(linksInList[linksInList.size()-1]);
newitem.Paste(lnk);
if (newitem.getValue() && this->doc == 0)
this->doc = newitem.getValue()->getDocument();
return linksInList.size()-1;
}
int ComboLinks::addLink(App::DocumentObject *linkObj, std::string linkSubname, QString itemText)
{
if(!_combo)
return 0;
_combo->addItem(itemText);
this->linksInList.push_back(new App::PropertyLinkSub());
App::PropertyLinkSub &newitem = *(linksInList[linksInList.size()-1]);
newitem.setValue(linkObj,std::vector<std::string>(1,linkSubname));
if (newitem.getValue() && this->doc == 0)
this->doc = newitem.getValue()->getDocument();
return linksInList.size()-1;
}
void ComboLinks::clear()
{
for(int i = 0 ; i < this->linksInList.size() ; i++){
delete linksInList[i];
}
if(this->_combo)
_combo->clear();
}
App::PropertyLinkSub &ComboLinks::getLink(int index) const
{
if (index < 0 || index > linksInList.size()-1)
throw Base::Exception("ComboLinks::getLink:Index out of range");
if (linksInList[index]->getValue() && doc && !(doc->isIn(linksInList[index]->getValue())))
throw Base::Exception("Linked object is not in the document; it may have been deleted");
return *(linksInList[index]);
}
App::PropertyLinkSub &ComboLinks::getCurrentLink() const
{
assert(_combo);
return getLink(_combo->currentIndex());
}
int ComboLinks::setCurrentLink(const App::PropertyLinkSub &lnk)
{
for(int i = 0 ; i < linksInList.size() ; i++) {
App::PropertyLinkSub &it = *(linksInList[i]);
if(lnk.getValue() == it.getValue() && lnk.getSubValues() == it.getSubValues()){
bool wasBlocked = _combo->signalsBlocked();
_combo->blockSignals(true);
_combo->setCurrentIndex(i);
_combo->blockSignals(wasBlocked);
return i;
}
}
return -1;
}

View File

@ -1,247 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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 *
* *
******************************************************************************/
#ifndef GUI_TASKVIEW_TaskTransformedParameters_H
#define GUI_TASKVIEW_TaskTransformedParameters_H
#include <QComboBox>
#include <Mod/Part/App/Part2DObject.h>
#include <Gui/TaskView/TaskView.h>
#include <Gui/Selection.h>
#include "TaskFeatureParameters.h"
#include "TaskTransformedMessages.h"
#include "ViewProviderTransformed.h"
class QListWidget;
namespace Part {
class Feature;
}
namespace PartDesign {
class Transformed;
}
namespace PartDesignGui {
class TaskMultiTransformParameters;
/**
* @brief The ComboLinks class is a helper class that binds to a combo box and
* provides an interface to add links, retrieve links and select items by link
* value
*/
class ComboLinks
{
public:
/**
* @brief ComboLinks constructor.
* @param combo. It will be cleared as soon as it is bound. Don't add or
* remove items from the combo directly, otherwise internal tracking list
* will go out of sync, and crashes may result.
*/
ComboLinks(QComboBox &combo);
ComboLinks() {_combo = 0; doc = 0;};
void setCombo(QComboBox &combo) {assert(_combo == 0); this->_combo = &combo; _combo->clear();}
/**
* @brief addLink adds an item to the combo. Doesn't check for duplicates.
* @param lnk can be a link to NULL, which is usually used for special item "Select Reference"
* @param itemText
* @return
*/
int addLink(const App::PropertyLinkSub &lnk, QString itemText);
int addLink(App::DocumentObject* linkObj, std::string linkSubname, QString itemText);
void clear();
App::PropertyLinkSub& getLink(int index) const;
/**
* @brief getCurrentLink
* @return the link corresponding to the selected item. May be null link,
* which is usually used to indicate a "Select reference..." special item.
* Otherwise, the link is automatically tested for validity (oif an object
* doesn't exist in the document, an exception will be thrown.)
*/
App::PropertyLinkSub& getCurrentLink() const;
/**
* @brief setCurrentLink selects the item with the link that matches the
* argument. If there is no such link in the list, -1 is returned and
* selected item is not changed. Signals from combo are blocked in this
* function.
* @param lnk
* @return the index of an item that was selected, -1 if link is not in the list yet.
*/
int setCurrentLink(const App::PropertyLinkSub &lnk);
QComboBox& combo(void) const {assert(_combo); return *_combo;};
~ComboLinks() {_combo = 0; clear();};
private:
QComboBox* _combo;
App::Document* doc;
std::vector<App::PropertyLinkSub*> linksInList;
};
/**
The transformed subclasses will be used in two different modes:
1. As a stand-alone feature
2. As a container that stores transformation info for a MultiTransform feature. In this case
the flag insideMultiTransform is set to true.
Because in the second case there is no ViewProvider, some special methods are required to
access the underlying FeatureTransformed object in two different ways.
**/
class TaskTransformedParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver
{
Q_OBJECT
public:
/// Constructor for task with ViewProvider
TaskTransformedParameters(ViewProviderTransformed *TransformedView, QWidget *parent = 0);
/// Constructor for task with parent task (MultiTransform mode)
TaskTransformedParameters(TaskMultiTransformParameters *parentTask);
virtual ~TaskTransformedParameters();
/// Returns the originals property of associated top feeature object
const std::vector<App::DocumentObject*> & getOriginals(void) const;
/// Get the TransformedFeature object associated with this task
// Either through the ViewProvider or the currently active subFeature of the parentTask
Part::Feature *getBaseObject() const;
/// Get the sketch object of the first original either of the object associated with this feature or with the parent feature (MultiTransform mode)
App::DocumentObject* getSketchObject() const;
void exitSelectionMode();
virtual void apply() = 0;
protected Q_SLOTS:
/**
* Returns the base transformation view provider
* For stand alone features it will be view provider associated with this object
* For features inside multitransform it will be the view provider of the multitransform object
*/
PartDesignGui::ViewProviderTransformed *getTopTransformedView () const;
/**
* Returns the base transformated object
* For stand alone features it will be objects associated with this object
* For features inside multitransform it will be the base multitransform object
*/
PartDesign::Transformed *getTopTransformedObject () const;
/// Connect the subTask OK button to the MultiTransform task
virtual void onSubTaskButtonOK() {}
void onButtonAddFeature(const bool checked);
void onButtonRemoveFeature(const bool checked);
virtual void onFeatureDeleted(void)=0;
protected:
/**
* Returns the base transformation
* For stand alone features it will be objects associated with the view provider
* For features inside multitransform it will be the parent's multitransform object
*/
PartDesign::Transformed *getObject () const;
const bool originalSelected(const Gui::SelectionChanges& msg);
/// Recompute either this feature or the parent feature (MultiTransform mode)
void recomputeFeature();
void hideObject();
void showObject();
void hideBase();
void showBase();
void addReferenceSelectionGate(bool edge, bool face);
bool isViewUpdated() const;
int getUpdateViewTimeout() const;
protected:
virtual void changeEvent(QEvent *e) = 0;
virtual void onSelectionChanged(const Gui::SelectionChanges& msg) = 0;
virtual void clearButtons()=0;
static void removeItemFromListWidget(QListWidget* widget, const char* itemstr);
App::DocumentObject* getPartPlanes(const char* str) const;
App::DocumentObject* getPartLines(const char* str) const;
void fillAxisCombo(ComboLinks &combolinks, Part::Part2DObject *sketch);
void fillPlanesCombo(ComboLinks &combolinks, Part2DObject *sketch);
protected:
QWidget* proxy;
ViewProviderTransformed *TransformedView;
enum selectionModes { none, addFeature, removeFeature, reference };
selectionModes selectionMode;
/// The MultiTransform parent task of this task
TaskMultiTransformParameters* parentTask;
/// Flag indicating whether this object is a container for MultiTransform
bool insideMultiTransform;
/// Lock updateUI(), applying changes to the underlying feature and calling recomputeFeature()
bool blockUpdate;
};
/// simulation dialog for the TaskView
class TaskDlgTransformedParameters : public PartDesignGui::TaskDlgFeatureParameters
{
Q_OBJECT
public:
TaskDlgTransformedParameters(ViewProviderTransformed *TransformedView);
virtual ~TaskDlgTransformedParameters() {}
ViewProviderTransformed* getTransformedView() const
{ return static_cast<ViewProviderTransformed*>(vp); }
public:
/// is called by the framework if the dialog is accepted (Ok)
virtual bool accept();
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
<<<<<<< a6aea83ec9ef83d52a06178b32175b3e79f73c65
virtual bool isAllowedAlterDocument(void) const
{ return false; }
/// returns for Close and Help button
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const
{ return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; }
=======
>>>>>>> PartDesign: make transform parameter dialogs use common base code with other dialogs
protected:
TaskTransformedParameters *parameter;
TaskTransformedMessages *message;
};
} //namespace PartDesignGui
#endif // GUI_TASKVIEW_TASKAPPERANCE_H

View File

@ -1,410 +0,0 @@
/******************************************************************************
* Copyright (c)2012 Jan Rheinlaender <jrheinlaender@users.sourceforge.net> *
* *
* 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"
#ifndef _PreComp_
# include <Bnd_Box.hxx>
# include <BRep_Tool.hxx>
# include <BRepBndLib.hxx>
# include <BRepMesh_IncrementalMesh.hxx>
# include <Standard_Version.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <Poly_Triangulation.hxx>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoDrawStyle.h>
# include <Inventor/nodes/SoIndexedFaceSet.h>
# include <Inventor/nodes/SoMaterial.h>
# include <Inventor/nodes/SoMultipleCopy.h>
# include <Inventor/nodes/SoNormal.h>
# include <Inventor/nodes/SoPickStyle.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoShapeHints.h>
# include <Inventor/nodes/SoTransparencyType.h>
# include <QAction>
# include <QMenu>
# include <QMessageBox>
#endif
#include "Workbench.h"
#include "ViewProviderTransformed.h"
#include "TaskTransformedParameters.h"
#include <Base/Console.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Mod/Part/App/TopoShape.h>
#include <Mod/PartDesign/App/FeatureAdditive.h>
#include <Mod/PartDesign/App/FeatureSubtractive.h>
#include <Mod/PartDesign/App/FeatureTransformed.h>
using namespace PartDesignGui;
PROPERTY_SOURCE(PartDesignGui::ViewProviderTransformed,PartDesignGui::ViewProvider)
void ViewProviderTransformed::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
QAction* act;
act = menu->addAction(QObject::tr((std::string("Edit ") + featureName + " feature").c_str()), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderTransformed::setEdit(int ModNum)
{
pcRejectedRoot = new SoSeparator();
pcRejectedRoot->ref();
SoPickStyle* rejectedPickStyle = new SoPickStyle();
rejectedPickStyle->style = SoPickStyle::UNPICKABLE;
SoShapeHints* rejectedHints = new SoShapeHints();
rejectedHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
rejectedHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
SoMaterialBinding* rejectedBind = new SoMaterialBinding();
SoTransparencyType* rejectedTransparencyType = new SoTransparencyType();
rejectedTransparencyType->value.setValue(SoGLRenderAction::BLEND);
SoMaterial* rejectedMaterial = new SoMaterial();
rejectedMaterial->diffuseColor.set1Value(0,SbColor(1.f,0.f,0.f));
rejectedMaterial->transparency.setValue(0.6f);
SoDrawStyle* rejectedFaceStyle = new SoDrawStyle();
rejectedFaceStyle->style = SoDrawStyle::FILLED;
SoNormalBinding* rejectedNormb = new SoNormalBinding();
rejectedNormb->value = SoNormalBinding::PER_VERTEX_INDEXED;
// just faces with no edges or points
pcRejectedRoot->addChild(rejectedPickStyle);
pcRejectedRoot->addChild(rejectedTransparencyType);
pcRejectedRoot->addChild(rejectedBind);
pcRejectedRoot->addChild(rejectedMaterial);
pcRejectedRoot->addChild(rejectedHints);
pcRejectedRoot->addChild(rejectedFaceStyle);
pcRejectedRoot->addChild(rejectedNormb); // NOTE: The code relies on the last child added here being index 6
pcRoot->addChild(pcRejectedRoot);
recomputeFeature();
return true;
}
void ViewProviderTransformed::unsetEdit(int ModNum)
{
// return to the WB we were in before editing the PartDesign feature
Gui::Command::assureWorkbench(oldWb.c_str());
if (ModNum == ViewProvider::Default) {
// when pressing ESC make sure to close the dialog
Gui::Control().closeDialog();
if ((PartDesignGui::ActivePartObject != NULL) && (oldTip != NULL)) {
Gui::Selection().clearSelection();
Gui::Selection().addSelection(oldTip->getDocument()->getName(), oldTip->getNameInDocument());
Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')");
oldTip = NULL;
} else {
oldTip = NULL;
}
}
else {
PartGui::ViewProviderPart::unsetEdit(ModNum);
}
while (pcRejectedRoot->getNumChildren() > 7) {
SoSeparator* sep = static_cast<SoSeparator*>(pcRejectedRoot->getChild(7));
SoMultipleCopy* rejectedTrfms = static_cast<SoMultipleCopy*>(sep->getChild(2));
rejectedTrfms ->removeAllChildren();
sep->removeChild(1);
sep->removeChild(0);
pcRejectedRoot ->removeChild(7);
}
pcRejectedRoot->removeAllChildren();
pcRoot->removeChild(pcRejectedRoot);
pcRejectedRoot->unref();
}
bool ViewProviderTransformed::onDelete(const std::vector<std::string> &s)
{
return ViewProvider::onDelete(s);
}
const bool ViewProviderTransformed::checkDlgOpen(TaskDlgTransformedParameters* transformedDlg) {
// When double-clicking on the item for this feature the
// object unsets and sets its edit mode without closing
// the task panel
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
transformedDlg = qobject_cast<TaskDlgTransformedParameters *>(dlg);
if ((transformedDlg != NULL) && (transformedDlg->getTransformedView() != this))
transformedDlg = NULL; // another transformed feature left open its task panel
if ((dlg != NULL) && (transformedDlg == NULL)) {
QMessageBox msgBox;
msgBox.setText(QObject::tr("A dialog is already open in the task panel"));
msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?"));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
int ret = msgBox.exec();
if (ret == QMessageBox::Yes)
Gui::Control().reject();
else
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
// Continue (usually in virtual method setEdit())
return true;
}
void ViewProviderTransformed::recomputeFeature(void)
{
PartDesign::Transformed* pcTransformed = static_cast<PartDesign::Transformed*>(getObject());
pcTransformed->getDocument()->recomputeFeature(pcTransformed);
const std::vector<App::DocumentObjectExecReturn*> log = pcTransformed->getDocument()->getRecomputeLog();
<<<<<<< eb9a4ab96f8703de819cdc5e405217b784ccff90
unsigned rejected = pcTransformed->getRejectedTransformations().size();
QString msg = QString::fromLatin1("%1");
=======
PartDesign::Transformed::rejectedMap rejected_trsf = pcTransformed->getRejectedTransformations();
unsigned rejected = 0;
for (PartDesign::Transformed::rejectedMap::const_iterator r = rejected_trsf.begin(); r != rejected_trsf.end(); r++)
rejected += r->second.size();
QString msg = QString::fromAscii("%1");
>>>>>>> Enable multiple originals for the transformed features
if (rejected > 0) {
msg = QString::fromLatin1("<font color='orange'>%1<br/></font>\r\n%2");
if (rejected == 1)
msg = msg.arg(QObject::tr("One transformed shape does not intersect support"));
else {
msg = msg.arg(QObject::tr("%1 transformed shapes do not intersect support"));
msg = msg.arg(rejected);
}
}
if (log.size() > 0) {
msg = msg.arg(QString::fromLatin1("<font color='red'>%1<br/></font>"));
msg = msg.arg(QString::fromStdString(log.back()->Why));
} else {
msg = msg.arg(QString::fromLatin1("<font color='green'>%1<br/></font>"));
msg = msg.arg(QObject::tr("Transformation succeeded"));
}
signalDiagnosis(msg);
// Clear all the rejected stuff
while (pcRejectedRoot->getNumChildren() > 7) {
SoSeparator* sep = static_cast<SoSeparator*>(pcRejectedRoot->getChild(7));
SoMultipleCopy* rejectedTrfms = static_cast<SoMultipleCopy*>(sep->getChild(2));
rejectedTrfms ->removeAllChildren();
sep->removeChild(1);
sep->removeChild(0);
pcRejectedRoot ->removeChild(7);
}
for (PartDesign::Transformed::rejectedMap::const_iterator o = rejected_trsf.begin(); o != rejected_trsf.end(); o++) {
if (o->second.empty()) continue;
TopoDS_Shape shape;
if ((o->first)->getTypeId().isDerivedFrom(PartDesign::Additive::getClassTypeId())) {
PartDesign::Additive* addFeature = static_cast<PartDesign::Additive*>(o->first);
shape = addFeature->AddShape.getShape()._Shape;
} else if ((o->first)->getTypeId().isDerivedFrom(PartDesign::Subtractive::getClassTypeId())) {
PartDesign::Subtractive* subFeature = static_cast<PartDesign::Subtractive*>(o->first);
shape = subFeature->SubShape.getShape()._Shape;
}
if (shape.IsNull()) continue;
// Display the rejected transformations in red
TopoDS_Shape cShape(shape);
try {
// calculating the deflection value
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
{
Bnd_Box bounds;
BRepBndLib::Add(cShape, bounds);
bounds.SetGap(0.0);
bounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
}
Standard_Real deflection = ((xMax-xMin)+(yMax-yMin)+(zMax-zMin))/300.0 * Deviation.getValue();
// create or use the mesh on the data structure
// Note: This DOES have an effect on cShape
#if OCC_VERSION_HEX >= 0x060600
Standard_Real AngDeflectionRads = AngularDeflection.getValue() / 180.0 * M_PI;
BRepMesh_IncrementalMesh(cShape,deflection,Standard_False,
AngDeflectionRads,Standard_True);
#else
BRepMesh_IncrementalMesh(cShape,deflection);
#endif
// We must reset the location here because the transformation data
// are set in the placement property
TopLoc_Location aLoc;
cShape.Location(aLoc);
// count triangles and nodes in the mesh
int nbrTriangles=0, nbrNodes=0;
TopExp_Explorer Ex;
for (Ex.Init(cShape,TopAbs_FACE);Ex.More();Ex.Next()) {
Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(TopoDS::Face(Ex.Current()), aLoc);
// Note: we must also count empty faces
if (!mesh.IsNull()) {
nbrTriangles += mesh->NbTriangles();
nbrNodes += mesh->NbNodes();
}
}
// create memory for the nodes and indexes
SoCoordinate3* rejectedCoords = new SoCoordinate3();
rejectedCoords ->point .setNum(nbrNodes);
SoNormal* rejectedNorms = new SoNormal();
rejectedNorms ->vector .setNum(nbrNodes);
SoIndexedFaceSet* rejectedFaceSet = new SoIndexedFaceSet();
rejectedFaceSet ->coordIndex .setNum(nbrTriangles*4);
// get the raw memory for fast fill up
SbVec3f* verts = rejectedCoords ->point .startEditing();
SbVec3f* norms = rejectedNorms ->vector .startEditing();
int32_t* index = rejectedFaceSet ->coordIndex .startEditing();
// preset the normal vector with null vector
for (int i=0; i < nbrNodes; i++)
norms[i]= SbVec3f(0.0,0.0,0.0);
int ii = 0,FaceNodeOffset=0,FaceTriaOffset=0;
for (Ex.Init(cShape, TopAbs_FACE); Ex.More(); Ex.Next(),ii++) {
TopLoc_Location aLoc;
const TopoDS_Face &actFace = TopoDS::Face(Ex.Current());
// get the mesh of the shape
Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(actFace,aLoc);
if (mesh.IsNull()) continue;
// getting the transformation of the shape/face
gp_Trsf myTransf;
Standard_Boolean identity = true;
if (!aLoc.IsIdentity()) {
identity = false;
myTransf = aLoc.Transformation();
}
// getting size of node and triangle array of this face
int nbNodesInFace = mesh->NbNodes();
int nbTriInFace = mesh->NbTriangles();
// check orientation
TopAbs_Orientation orient = actFace.Orientation();
// cycling through the poly mesh
const Poly_Array1OfTriangle& Triangles = mesh->Triangles();
const TColgp_Array1OfPnt& Nodes = mesh->Nodes();
for (int g=1; g <= nbTriInFace; g++) {
// Get the triangle
Standard_Integer N1,N2,N3;
Triangles(g).Get(N1,N2,N3);
// change orientation of the triangle if the face is reversed
if ( orient != TopAbs_FORWARD ) {
Standard_Integer tmp = N1;
N1 = N2;
N2 = tmp;
}
// get the 3 points of this triangle
gp_Pnt V1(Nodes(N1)), V2(Nodes(N2)), V3(Nodes(N3));
// transform the vertices to the place of the face
if (!identity) {
V1.Transform(myTransf);
V2.Transform(myTransf);
V3.Transform(myTransf);
}
// calculating per vertex normals
// Calculate triangle normal
gp_Vec v1(V1.X(),V1.Y(),V1.Z()),v2(V2.X(),V2.Y(),V2.Z()),v3(V3.X(),V3.Y(),V3.Z());
gp_Vec Normal = (v2-v1)^(v3-v1);
// add the triangle normal to the vertex normal for all points of this triangle
norms[FaceNodeOffset+N1-1] += SbVec3f(Normal.X(),Normal.Y(),Normal.Z());
norms[FaceNodeOffset+N2-1] += SbVec3f(Normal.X(),Normal.Y(),Normal.Z());
norms[FaceNodeOffset+N3-1] += SbVec3f(Normal.X(),Normal.Y(),Normal.Z());
// set the vertices
verts[FaceNodeOffset+N1-1].setValue((float)(V1.X()),(float)(V1.Y()),(float)(V1.Z()));
verts[FaceNodeOffset+N2-1].setValue((float)(V2.X()),(float)(V2.Y()),(float)(V2.Z()));
verts[FaceNodeOffset+N3-1].setValue((float)(V3.X()),(float)(V3.Y()),(float)(V3.Z()));
// set the index vector with the 3 point indexes and the end delimiter
index[FaceTriaOffset*4+4*(g-1)] = FaceNodeOffset+N1-1;
index[FaceTriaOffset*4+4*(g-1)+1] = FaceNodeOffset+N2-1;
index[FaceTriaOffset*4+4*(g-1)+2] = FaceNodeOffset+N3-1;
index[FaceTriaOffset*4+4*(g-1)+3] = SO_END_FACE_INDEX;
}
// counting up the per Face offsets
FaceNodeOffset += nbNodesInFace;
FaceTriaOffset += nbTriInFace;
}
// normalize all normals
for (int i=0; i < nbrNodes; i++)
norms[i].normalize();
// end the editing of the nodes
rejectedCoords ->point .finishEditing();
rejectedNorms ->vector .finishEditing();
rejectedFaceSet ->coordIndex .finishEditing();
// fill in the transformation matrices
SoMultipleCopy* rejectedTrfms = new SoMultipleCopy();
rejectedTrfms->matrix.setNum((o->second).size());
SbMatrix* mats = rejectedTrfms->matrix.startEditing();
std::list<gp_Trsf>::const_iterator trsf = (o->second).begin();
for (unsigned int i=0; i < (o->second).size(); i++,trsf++) {
Base::Matrix4D mat;
Part::TopoShape::convertToMatrix(*trsf,mat);
mats[i] = convert(mat);
}
rejectedTrfms->matrix.finishEditing();
rejectedTrfms->addChild(rejectedFaceSet);
SoSeparator* sep = new SoSeparator();
sep->addChild(rejectedCoords);
sep->addChild(rejectedNorms);
sep->addChild(rejectedTrfms);
pcRejectedRoot->addChild(sep);
}
catch (...) {
Base::Console().Error("Cannot compute Inventor representation for the rejected transformations of shape of %s.\n",
pcTransformed->getNameInDocument());
}
}
}

View File

@ -1,76 +0,0 @@
# PartDesign gui init module
# (c) 2003 Juergen Riegel
#
# Gathering all the information to start FreeCAD
# This is the second one of three init scripts, the third one
# runs when the gui is up
#***************************************************************************
#* (c) Juergen Riegel (juergen.riegel@web.de) 2002 *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* FreeCAD 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 Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#* Juergen Riegel 2002 *
#***************************************************************************/
class PartDesignWorkbench ( Workbench ):
"PartDesign workbench object"
def __init__(self):
self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/PartDesign/Resources/icons/PartDesignWorkbench.svg"
self.__class__.MenuText = "Part Design"
self.__class__.ToolTip = "Part Design workbench"
def Initialize(self):
# load the module
try:
from WizardShaft import WizardShaft
except ImportError:
print "Wizard shaft module cannot be loaded"
try:
from FeatureHole import HoleGui
except:
pass
<<<<<<< b5588a8b68f0650311b83fab5cf5afffd31f9a5f
import PartDesignGui
import PartDesign
try:
import InvoluteGearFeature
except ImportError:
print "Involute gear module cannot be loaded"
try:
from FeatureHole import HoleGui
except:
pass
=======
import PartDesignGui
import PartDesign
try:
import InvoluteGearFeature
except ImportError:
print "Involute gear module cannot be loaded"
#try:
# from FeatureHole import HoleGui
#except:
# pass
>>>>>>> remove hole feature
def GetClassName(self):
return "PartDesignGui::Workbench"
Gui.addWorkbench(PartDesignWorkbench())

File diff suppressed because it is too large Load Diff