for aResIndex in range(self.Part.size(aResultType)):
anObject = self.Part.object(aResultType, aResIndex)
aResult = model.objectToResult(anObject)
- # do nt export picture
- if aResult.hasTextureFile() is True:
+ # do not export picture
+ if aResult.hasTexture() is True:
continue
if not aResult is None:
if (not aResult.shape() or aResult.shape().isNull()) and isPart:
aResObject = aPartDoc.object(model.ModelAPI_ResultBody_group(), aResId)
aRes = model.objectToResult(aResObject)
#do not export images
- if aRes.hasTextureFile() is True:
+ if aRes.hasTexture() is True:
continue
aResFeatureId = str(aPartDoc.feature(aRes).data().featureId())
if aResFeatureId in aFeaturesIndices:
#
INCLUDE(Common)
+INCLUDE(UseQtExt)
SET(PROJECT_HEADERS
ExchangeAPI.h
ModelAPI
ModelHighAPI
GeomAlgoAPI
+ ${QT_LIBRARIES}
)
INCLUDE_DIRECTORIES(
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/ModelHighAPI
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
+ ${QT_INCLUDES}
)
# Plugin headers dependency
${PROJECT_SOURCE_DIR}/src/ExchangePlugin
)
+# additional preprocessor / compiler flags
+ADD_DEFINITIONS(${QT_DEFINITIONS})
+
#TODO(spo): is ${OpenCASCADE_DEFINITIONS} necessary?
ADD_DEFINITIONS(-DEXCHANGEAPI_EXPORTS ${OpenCASCADE_DEFINITIONS})
ADD_LIBRARY(ExchangeAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
#include <ModelHighAPI_Tools.h>
//--------------------------------------------------------------------------------------
#include <ModelAPI_AttributeStringArray.h>
+#include <ModelAPI_AttributeImage.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Tools.h>
#include <GeomAlgoAPI_Tools.h>
//--------------------------------------------------------------------------------------
#include <algorithm>
+//--------------------------------------------------------------------------------------
+#include <QPixmap>
ExchangeAPI_Import::ExchangeAPI_Import(
const std::shared_ptr<ModelAPI_Feature> & theFeature)
std::string aPartName = theDumper.name(aBase->document());
std::string aFilePath =
- aBase->string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID())->value();
+ aBase->string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID())->value();
+
+ /*
+ // Store image from result into a tmp file
+ ResultPtr aResult = aBase->firstResult();
+ if (aResult.get() && aResult->hasTexture()) {
+ // get image data
+ int aWidth, aHeight;
+ std::string aFormat;
+ std::list<unsigned char> aByteList;
+ AttributeImagePtr anImageAttr =
+ aResult->data()->image(ModelAPI_ResultBody::IMAGE_ID());
+ anImageAttr->texture(aWidth, aHeight, aByteList, aFormat);
+
+ // convert image data to QPixmap
+ uchar* arr = new uchar[aByteList.size()];
+ std::copy(aByteList.begin(), aByteList.end(), arr);
+ QImage image (arr, aWidth, aHeight, QImage::Format_ARGB32);
+ QPixmap pixmap = QPixmap::fromImage( image );
+
+ // get tmp file name
+ std::string aTmpFilePath =
+ "/dn25/salome/jfa/BUGS/SHAPER/2_2_5_Saving_Images/tmp_image.";
+ aTmpFilePath += aFormat;
+
+ // write image to tmp file
+ if (pixmap.save(aTmpFilePath.c_str())) {
+
+ // dump tmp file name
+ aFilePath = aTmpFilePath;
+ }
+ delete [] arr;
+ }
+ */
theDumper << aBase << " = model.addImportImage(" << aPartName << ", \""
<< aFilePath << "\")" << std::endl;
INCLUDE(Common)
INCLUDE(UnitTest)
+INCLUDE(UseQtExt)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
${PROJECT_SOURCE_DIR}/src/Config
${PROJECT_SOURCE_DIR}/src/ConstructionPlugin
${PROJECT_SOURCE_DIR}/src/PartSetPlugin
${OpenCASCADE_INCLUDE_DIR}
+ ${QT_INCLUDES}
)
+# additional preprocessor / compiler flags
+ADD_DEFINITIONS(${QT_DEFINITIONS})
+
SET(PROJECT_HEADERS
ExchangePlugin.h
ExchangePlugin_Plugin.h
GeomAlgoAPI
GeomValidators
XAOShaper
+ ${QT_LIBRARIES}
)
# default dump approaches (will be set if not initialized)
/// do not export pictures
ResultPtr aBodyContext =
std::dynamic_pointer_cast<ModelAPI_Result>(anAttrSelection->context());
- if(aBodyContext->hasTextureFile())
+ if (aBodyContext->hasTexture())
continue;
std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
AttributeSelectionListPtr aSelection = selectionList(XAO_SELECTION_LIST_ID());
bool aIsSelection = aSelection->isInitialized() && aSelection->size() > 0;
if (aIsSelection) { // a mode for export to geom result by result
- for(int a = 0; a < aSelection->size(); a++) {
+ for (int a = 0; a < aSelection->size(); a++) {
AttributeSelectionPtr anAttr = aSelection->value(a);
ResultPtr aBodyContext =
std::dynamic_pointer_cast<ModelAPI_Result>(anAttr->context());
if (aBodyContext.get() && !aBodyContext->isDisabled() && aBodyContext->shape().get()) {
/// do not export pictures
- if(aBodyContext->hasTextureFile()){
+ if (aBodyContext->hasTexture()){
anExCludedIsImage = true;
continue;
}
void ExchangePlugin_Import_Image::execute()
{
- AttributeStringPtr aFilePathAttr = string(ExchangePlugin_ImportBase::FILE_PATH_ID());
+ AttributeStringPtr aFilePathAttr = string(ExchangePlugin_ImportBase::FILE_PATH_ID());
std::string aFilePath = aFilePathAttr->value();
if (aFilePath.empty()) {
setError("File path is empty.");
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeStringArray.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeImage.h>
#include <ModelAPI_AttributeTables.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeInteger.h>
#include <ExchangePlugin_Tools.h>
+#include <QPixmap>
/*
* Request for initialization of data model of the feature: adding all attributes
void ExchangePlugin_Import_ImageFeature::importFile(const std::string& theFileName)
{
-
std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
- std::string theTextureFileName = "";
- // Perform the import
std::string anError;
- std::shared_ptr<GeomAPI_Shape> aGeomShape;
- if (anExtension == "PNG" || anExtension == "GIF" ||
- anExtension == "TIFF" || anExtension == "JPE" ||
- anExtension == "JPG" || anExtension == "JPEG" ||
- anExtension == "BMP"|| anExtension == "PPM"
- ) {
- aGeomShape = ImageImport(theFileName, anError);
- if(anError == "")
- theTextureFileName = theFileName;
- } else {
- anError = "Unsupported format: " + anExtension;
- }
- // Check if shape is valid
- if (!anError.empty()) {
- setError("An error occurred while importing " + theFileName + ": " + anError);
- return;
- }
+ if (anExtension == "PNG" || anExtension == "GIF" ||
+ anExtension == "TIFF" || anExtension == "JPE" ||
+ anExtension == "JPEG" || anExtension == "JPG" ||
+ anExtension == "BMP" || anExtension == "PPM"
+ ) {
+ // Perform the import
+ QPixmap px (theFileName.c_str());
+ int aWidth = px.width();
+ int aHeight = px.height();
+ if (aWidth < 1 || aHeight < 1) {
+ setError("An error occurred while importing " + theFileName + ": invalid image");
+ return;
+ }
- // Pass the results into the model
- std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
- data()->setName(Locale::Convert::toWString(anObjectName));
+ std::shared_ptr<GeomAPI_Shape> aGeomShape = ImageImport(aWidth, aHeight, anError);
+
+ // Check if shape is valid
+ if (!anError.empty()) {
+ setError("An error occurred while importing " + theFileName + ": " + anError);
+ return;
+ }
+
+ // Pass the results into the model
+ std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
+ data()->setName(Locale::Convert::toWString(anObjectName));
+
+ auto resultBody = createResultBody(aGeomShape);
- auto resultBody = createResultBody(aGeomShape);
- resultBody->setTextureFile(theTextureFileName);
- setResult(resultBody);
+ // Store image in result body attribute
+ AttributeImagePtr anImageAttr = resultBody->data()->image(ModelAPI_ResultBody::IMAGE_ID());
+ if (anImageAttr.get() != NULL) {
+ QImage aQImage = px.toImage();
+ const uchar* aImageBytes = aQImage.bits();
+ std::list<unsigned char> aByteArray (aImageBytes, aImageBytes + aQImage.sizeInBytes());
+ anImageAttr->setTexture(aWidth, aHeight, aByteArray, anExtension);
+ }
+
+ setResult(resultBody);
+ }
+ else {
+ anError = "Unsupported format: " + anExtension;
+ setError("An error occurred while importing " + theFileName + ": " + anError);
+ }
}
assert(abs(dx-400) <= tol)
assert(abs(dy-258.5) <= tol)
assert(abs(dz-0) <= tol)
+assert(ImportImage_1.result().resultSubShapePair()[0].hasTexture())
+assert(Translation_1.result().resultSubShapePair()[0].hasTexture())
+assert(Scale_1.result().resultSubShapePair()[0].hasTexture())
#=============================================================================
# Change the image :
assert(abs(dx-448) <= tol)
assert(abs(dy-296.8) <= tol)
assert(abs(dz-0) <= tol)
+assert(ImportImage_1.result().resultSubShapePair()[0].hasTexture())
+assert(Translation_1.result().resultSubShapePair()[0].hasTexture())
+assert(Scale_1.result().resultSubShapePair()[0].hasTexture())
# Close SALOME GUI
assert(abs(dx-400) <= tol)
assert(abs(dy-258.5) <= tol)
assert(abs(dz-0) <= tol)
+assert(ImportImage_1.result().resultSubShapePair()[0].hasTexture())
+assert(Translation_1.result().resultSubShapePair()[0].hasTexture())
+assert(Scale_1.result().resultSubShapePair()[0].hasTexture())
#=============================================================================
# Change the image :
assert(abs(dx-560) <= tol)
assert(abs(dy-361.9) <= tol)
assert(abs(dz-0) <= tol)
+assert(ImportImage_1.result().resultSubShapePair()[0].hasTexture())
+assert(Translation_1.result().resultSubShapePair()[0].hasTexture())
+assert(Scale_1.result().resultSubShapePair()[0].hasTexture())
# Close SALOME GUI
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
#include <math.h>
#include <iostream>
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
- if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ ResultPtr aTextureSource;
+ if (!FeaturesPlugin_Tools::shapesFromSelectionList
+ (anObjectsSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
// Parameters of rotation.
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
aMakeShapeList, *anIt, "Rotated");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody);
setResult(aResultBody, aResultIndex++);
}
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
#include <math.h>
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
- if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ ResultPtr aTextureSource;
+ if (!FeaturesPlugin_Tools::shapesFromSelectionList
+ (anObjectsSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
std::shared_ptr<GeomAPI_Dir> aFirstDir, aSecondDir;
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
aMakeShapeList, *anIt, "Translated");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody);
setResult(aResultBody, aResultIndex++);
}
// Getting objects.
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
+ ResultPtr aTextureSource;
AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID());
- if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ if (!FeaturesPlugin_Tools::shapesFromSelectionList
+ (anObjectsSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
// Verify the start shape
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
aMakeShapeList, *anIt, "Placed");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody);
setResult(aResultBody, aResultIndex++);
}
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
#include <GeomAlgoAPI_MakeShapeList.h>
#include <GeomAlgoAPI_PointBuilder.h>
// Getting objects.
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
+ ResultPtr aTextureSource;
AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ anObjSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
std::string anError;
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
aMakeShapeList, *anIt, "Rotated");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody);
setResult(aResultBody, aResultIndex++);
}
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
static const std::string SCALE_VERSION_1("v9.5");
// Getting objects.
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
+ ResultPtr aTextureSource;
AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ anObjSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
// Getting the center point
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
aMakeShapeList, *anIt, "Scaled");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody);
setResult(aResultBody, aResultIndex++);
}
// Getting objects.
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
+ ResultPtr aTextureSource;
AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ anObjSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
// Getting the center point
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
aMakeShapeList, *anIt, "Scaled");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody);
setResult(aResultBody, aResultIndex++);
}
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
#include <FeaturesPlugin_Tools.h>
const std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theAlgo,
const std::list<std::shared_ptr<GeomAPI_Shape> >& theOriginalShapes,
std::shared_ptr<GeomAPI_Shape> theTargetShape, int& theResultIndex,
- std::string & theTextureFile)
+ const ResultPtr& theTextureSource)
{
// Store and name the result.
ResultBodyPtr aResultBody = document()->createBody(data(), theResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, theOriginalShapes, ListOfShape(),
theAlgo, theTargetShape, "Symmetried");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(theTextureSource, aResultBody);
setResult(aResultBody, theResultIndex++);
}
// Getting objects.
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
+ ResultPtr aTextureSource;
AttributeSelectionListPtr anObjSelList = selectionList(OBJECTS_LIST_ID());
if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ anObjSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
std::string anError;
ListOfShape aTopLevel;
anObjects.topLevelObjects(aTopLevel);
for (ListOfShape::iterator anIt = aTopLevel.begin(); anIt != aTopLevel.end(); ++anIt)
- buildResult(aMakeShapeList, anOriginalShapes, *anIt, aResultIndex, theTextureFile);
+ buildResult(aMakeShapeList, anOriginalShapes, *anIt, aResultIndex, aTextureSource);
// Remove the rest results if there were produced in the previous pass.
removeResults(aResultIndex);
#include <FeaturesPlugin.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
class GeomAPI_Trsf;
class GeomAlgoAPI_MakeShapeList;
void buildResult(const std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theAlgo,
const std::list<std::shared_ptr<GeomAPI_Shape> >& theOriginalShapes,
std::shared_ptr<GeomAPI_Shape> theTargetShape,
- int& theResultIndex, std::string &theTextureFile);
+ int& theResultIndex,
+ const ResultPtr& theTextureSource);
/// Create new result for the given part and transformation
void buildResult(std::shared_ptr<ModelAPI_ResultPart> theOriginal,
const std::shared_ptr<ModelAPI_AttributeSelectionList> theSelectionList,
const bool theStoreFullHierarchy,
GeomAPI_ShapeHierarchy& theHierarchy,
- std::list<ResultPtr>& theParts, std::string &theTextureFile)
+ std::list<ResultPtr>& theParts, ResultPtr& theTextureSource)
{
int aSize = theSelectionList->size();
- if(aSize == 1)
- {
+ if (aSize == 1) {
auto anObjectAttr = theSelectionList->value(0);
- if(anObjectAttr.get())
- {
+ if (anObjectAttr.get()) {
FeaturePtr aFeature = anObjectAttr->contextFeature();
- if(aFeature.get() && aFeature->results().size() == 1)
- {
- theTextureFile = aFeature->firstResult()->getTextureFile();
+ if (aFeature.get() && aFeature->results().size() == 1) {
+ theTextureSource = aFeature->firstResult();
}
- else
- {
- if(!aFeature.get())
- {
- auto aResult = anObjectAttr->context();
- if(aResult.get())
- {
- theTextureFile = aResult->getTextureFile();
+ else {
+ if (!aFeature.get()) {
+ auto aResult = anObjectAttr->context();
+ if (aResult.get()) {
+ theTextureSource = aResult;
}
}
}
const std::shared_ptr<ModelAPI_AttributeSelectionList> theSelectionList,
const bool theStoreFullHierarchy,
GeomAPI_ShapeHierarchy& theHierarchy,
- std::list<ResultPtr>& theParts, std::string& theTextureFile);
+ std::list<ResultPtr>& theParts,
+ ResultPtr& theTextureSource);
};
#endif /* FeaturesPlugin_Tools_H_ */
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
#include <GeomAPI_Ax1.h>
#include <GeomAPI_Edge.h>
// Getting objects.
GeomAPI_ShapeHierarchy anObjects;
std::list<ResultPtr> aParts;
- std::string theTextureFile;
+ ResultPtr aTextureSource;
AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECTS_LIST_ID());
- if (!FeaturesPlugin_Tools::shapesFromSelectionList(
- anObjectsSelList, isKeepSubShapes, anObjects, aParts, theTextureFile))
+ if (!FeaturesPlugin_Tools::shapesFromSelectionList
+ (anObjectsSelList, isKeepSubShapes, anObjects, aParts, aTextureSource))
return;
std::string anError;
ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
FeaturesPlugin_Tools::loadModifiedShapes(aResultBody, anOriginalShapes, ListOfShape(),
aMakeShapeList, *anIt, "Translated");
- aResultBody->setTextureFile(theTextureFile);
+ // Copy image data, if any
+ ModelAPI_Tools::copyImageAttribute(aTextureSource, aResultBody);
setResult(aResultBody, aResultIndex++);
}
${OpenCASCADE_DataExchange_LIBRARIES}
${OpenCASCADE_ModelingAlgorithms_LIBRARIES}
${OpenCASCADE_ApplicationFramework_LIBRARIES}
- ${QT_LIBRARIES}
)
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${OpenCASCADE_DEFINITIONS})
SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
-INCLUDE(UseQtExt)
# additional include directories
-INCLUDE_DIRECTORIES(${QT_INCLUDES})
-
INCLUDE_DIRECTORIES(
../GeomAPI
../GeomAlgoImpl
#include <GeomAlgoAPI_ImageImport.h>
-#include <QPixmap>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
-std::shared_ptr<GeomAPI_Shape> ImageImport(const std::string& theFileName,
- std::string& theError)
+std::shared_ptr<GeomAPI_Shape> ImageImport(const int width,
+ const int height,
+ std::string& theError)
{
TopoDS_Shape aResShape;
try
{
- QPixmap* pixmap = new QPixmap(theFileName.c_str());
- int height = pixmap->height();
- int width = pixmap->width();
-
- delete pixmap;
-
TopoDS_Vertex aTriVertexes[4];
gp_Pnt aPnt1( -0.5*width, -0.5*height, 0);
gp_Pnt aPnt2( 0.5*width, -0.5*height, 0);
#include <GeomAPI_Shape.h>
#include <string>
-#include <QPixmap>
+
/// Implementation of the import STL files algorithms
GEOMALGOAPI_EXPORT
-std::shared_ptr<GeomAPI_Shape> ImageImport(const std::string& theFileName,
- std::string& theError);
+std::shared_ptr<GeomAPI_Shape> ImageImport(const int theWidth,
+ const int theHeight,
+ std::string& theError);
#endif /* GEOMALGOAPI_IMAGEIMPORT_H_ */
Model_AttributeRefList.h
Model_AttributeRefAttrList.h
Model_AttributeBoolean.h
+ Model_AttributeImage.h
Model_AttributeIntArray.h
Model_AttributeString.h
Model_AttributeStringArray.h
Model_AttributeRefList.cpp
Model_AttributeRefAttrList.cpp
Model_AttributeBoolean.cpp
+ Model_AttributeImage.cpp
Model_AttributeIntArray.cpp
Model_AttributeString.cpp
Model_AttributeStringArray.cpp
--- /dev/null
+// Copyright (C) 2014-2021 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <Model_AttributeImage.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+
+#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_ByteArray.hxx>
+#include <TDataStd_Comment.hxx>
+#include <TDF_CopyLabel.hxx>
+
+void Model_AttributeImage::setTexture(const int theWidth,
+ const int theHeight,
+ const std::list<unsigned char>& theByteArray,
+ const std::string& theFormat,
+ const bool sendUpdated)
+{
+ if (theWidth > 0 && theHeight > 0 && theByteArray.size() > 0) { // set new data
+ // Find or create attributes
+ Handle_TDataStd_ByteArray aByteArray =
+ TDataStd_ByteArray::Set(myLab, 0, theByteArray.size() - 1);
+ Handle_TDataStd_IntegerArray aDimensions =
+ TDataStd_IntegerArray::Set(myLab, 0, 1);
+ Handle_TDataStd_Comment aFormat = TDataStd_Comment::Set(myLab, theFormat.c_str());
+
+ // Dimensions
+ aDimensions->SetValue(0, theWidth);
+ aDimensions->SetValue(1, theHeight);
+
+ // Texture
+ Handle(TColStd_HArray1OfByte) aNewArray =
+ new TColStd_HArray1OfByte(0, theByteArray.size() - 1);
+ std::list<unsigned char>::const_iterator itBA = theByteArray.begin();
+ for (int j = 0; itBA != theByteArray.end(); ++itBA, ++j) {
+ aNewArray->SetValue(j, (Standard_Byte)(*itBA));
+ }
+ aByteArray->ChangeArray(aNewArray);
+
+ if (sendUpdated)
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ else { // size is zero => arrays must be erased
+ bool isForgotten1 = myLab.ForgetAttribute(TDataStd_ByteArray::GetID());
+ bool isForgotten2 = myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
+ bool isForgotten3 = myLab.ForgetAttribute(TDataStd_Comment::GetID());
+
+ if (sendUpdated && (isForgotten1 || isForgotten2 || isForgotten3))
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+bool Model_AttributeImage::hasTexture()
+{
+ Handle_TDataStd_ByteArray aByteArray;
+ Handle_TDataStd_IntegerArray aDimensions;
+ if (myLab.FindAttribute(TDataStd_ByteArray::GetID(), aByteArray) == Standard_True &&
+ myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aDimensions) == Standard_True) {
+
+ // Dimensions
+ if (aDimensions->Value(0) > 0 && aDimensions->Value(1) > 0)
+ // Byte array
+ return aByteArray->Length() > 0;
+ }
+ return false;
+}
+
+bool Model_AttributeImage::texture(int& theWidth,
+ int& theHeight,
+ std::list<unsigned char>& theByteArray,
+ std::string& theFormat)
+{
+ // Init return values
+ theWidth = 0;
+ theHeight = 0;
+ theByteArray.clear();
+ theFormat = "";
+
+ Handle_TDataStd_ByteArray aByteArray;
+ Handle_TDataStd_IntegerArray aDimensions;
+ Handle_TDataStd_Comment aFormat;
+ if (myLab.FindAttribute(TDataStd_ByteArray::GetID(), aByteArray) == Standard_True &&
+ myLab.FindAttribute(TDataStd_IntegerArray::GetID(), aDimensions) == Standard_True &&
+ myLab.FindAttribute(TDataStd_Comment::GetID(), aFormat) == Standard_True) {
+
+ // Dimensions
+ theWidth = aDimensions->Value(0);
+ theHeight = aDimensions->Value(1);
+
+ // Texture
+ const Handle(TColStd_HArray1OfByte) byteArray = aByteArray->InternalArray();
+ for (int j = byteArray->Lower(); j <= byteArray->Upper(); j++) {
+ theByteArray.push_back((unsigned char)byteArray->Value( j ));
+ }
+
+ // Format
+ theFormat = TCollection_AsciiString(aFormat->Get()).ToCString();
+ return true;
+ }
+
+ return false;
+}
+
+void Model_AttributeImage::copyTo(AttributeImagePtr theTarget) const
+{
+ std::shared_ptr<Model_AttributeImage> aTarget =
+ std::dynamic_pointer_cast<Model_AttributeImage>(theTarget);
+ if (aTarget) {
+ //Model_AttributeSelectionList::copyAttrs(myLab, aTarget->myLab);
+ TDF_CopyLabel aCopyAlgo (myLab, aTarget->myLab);
+ aCopyAlgo.Perform();
+ aTarget->reinit();
+ }
+}
+
+Model_AttributeImage::Model_AttributeImage(TDF_Label& theLabel)
+{
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeImage::reinit()
+{
+ myIsInitialized = myLab.IsAttribute(TDataStd_ByteArray::GetID());
+}
--- /dev/null
+// Copyright (C) 2014-2021 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef MODEL_ATTRIBUTEIMAGE_H_
+#define MODEL_ATTRIBUTEIMAGE_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeImage.h>
+
+#include <TDF_Label.hxx>
+
+#include <string>
+
+/**\class Model_AttributeImage
+ * \ingroup DataModel
+ * \brief API for the attribute that contains image inside.
+ * Represented as the following OCCT attributes:
+ * TDataStd_ByteArray for the pixmap texture data,
+ * TDataStd_IntArray(2) for image dimensions (widht and height),
+ * TDataStd_String for image format.
+ */
+
+class Model_AttributeImage : public ModelAPI_AttributeImage
+{
+ /// Stores the label as the only reference to all data
+ TDF_Label myLab;
+
+ public:
+ /// Defines the value of the image attribute
+ MODEL_EXPORT virtual void setTexture(const int theWidth,
+ const int theHeight,
+ const std::list<unsigned char>& theByteArray,
+ const std::string& theFormat,
+ const bool sendUpdated = true);
+
+ /// Returns true, if texture width and height are non-zero
+ MODEL_EXPORT virtual bool hasTexture();
+
+ /// Returns the value of the image attribute
+ MODEL_EXPORT virtual bool texture(int& theWidth,
+ int& theHeight,
+ std::list<unsigned char>& theByteArray,
+ std::string& theFormat);
+
+ /// Copy the image data to the destination attribute
+ virtual void copyTo(std::shared_ptr<ModelAPI_AttributeImage> theTarget) const;
+
+ protected:
+ /// Initializes attibutes
+ Model_AttributeImage(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeSelection.h>
#include <Model_AttributeSelectionList.h>
#include <Model_AttributeIntArray.h>
+#include <Model_AttributeImage.h>
#include <Model_AttributeTables.h>
#include <Model_Events.h>
#include <Model_Expression.h>
anAttr = new Model_AttributeDoubleArray(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeTables::typeId()) {
anAttr = new Model_AttributeTables(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeImage::typeId()) {
+ anAttr = new Model_AttributeImage(anAttrLab);
}
// create also GeomData attributes here because only here the OCAF structure is known
else if (theAttrType == GeomData_Point::typeId()) {
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDoubleArray, realArray);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeTables, tables);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeImage, image);
std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
{
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeStringArray.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeImage.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Folder.h>
/// Returns the attribute that contains string values array
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeTables>
tables(const std::string& theID);
+ /// Returns the attribute that contains image
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeImage>
+ image(const std::string& theID);
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
#include <ModelAPI_Object.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeImage.h>
#include <Model_Data.h>
#include <Events_Loop.h>
#include <GeomAPI_ShapeIterator.h>
delete myBuilder;
}
+void Model_ResultBody::initAttributes()
+{
+ ModelAPI_Result::initAttributes();
+ // append the image attribute. It is empty, the attribute will be filled by a request
+ data()->addAttribute(IMAGE_ID(), ModelAPI_AttributeImage::typeId())->setIsArgument(false);
+}
+
bool Model_ResultBody::generated(const GeomShapePtr& theNewShape,
const std::string& theName, const bool theCheckIsInResult)
{
myHistoryCash.Clear();
}
-void Model_ResultBody::setTextureFile(const std::string & theTextureFile)
-{
- ModelAPI_Result::setTextureFile(theTextureFile);
- for( auto sub : mySubs){
- sub->setTextureFile(theTextureFile);
- }
- for(auto map : mySubsMap){
- map.first->setTextureFile(theTextureFile);
- }
-}
-
bool Model_ResultBody::isConnectedTopology()
{
TDF_Label aDataLab = std::dynamic_pointer_cast<Model_Data>(data())->label();
}
}
+bool Model_ResultBody::hasTexture()
+{
+ AttributeImagePtr anImageAttr =
+ data()->image(ModelAPI_ResultBody::IMAGE_ID());
+ if (anImageAttr.get()) {
+ return anImageAttr->hasTexture();
+ }
+ return false;
+}
+
// adds to the theSubSubs map all sub-shapes of theSub if it is compound of compsolid
static void collectSubs(
const GeomShapePtr theSub, TopTools_MapOfShape& theSubSubs, const bool theOneLevelMore)
/// Removes the stored builders
MODEL_EXPORT virtual ~Model_ResultBody();
+ /// Request for initialization of data model of the result body: adding all attributes
+ virtual void initAttributes();
+
/// Records the subshape newShape which was generated during a topological construction.
/// As an example, consider the case of a face generated in construction of a box.
MODEL_EXPORT virtual bool generated(const GeomShapePtr& theNewShape,
MODEL_EXPORT virtual void cleanCash() override;
/// sets the texture file
- MODEL_EXPORT virtual void setTextureFile(const std::string & theTextureFile) override;
+ MODEL_EXPORT virtual bool hasTexture() override;
protected:
ModelAPI.h
ModelAPI_Attribute.h
ModelAPI_AttributeBoolean.h
+ ModelAPI_AttributeImage.h
ModelAPI_AttributeIntArray.h
ModelAPI_AttributeDocRef.h
ModelAPI_AttributeDouble.h
SET(PROJECT_SOURCES
ModelAPI_Attribute.cpp
ModelAPI_AttributeBoolean.cpp
+ ModelAPI_AttributeImage.cpp
ModelAPI_AttributeIntArray.cpp
ModelAPI_AttributeDocRef.cpp
ModelAPI_AttributeDouble.cpp
--- /dev/null
+// Copyright (C) 2014-2021 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <ModelAPI_AttributeImage.h>
+
+
+std::string ModelAPI_AttributeImage::attributeType()
+{
+ return typeId();
+}
+
+/// To virtually destroy the fields of successors
+ModelAPI_AttributeImage::~ModelAPI_AttributeImage()
+{
+}
+
+ModelAPI_AttributeImage::ModelAPI_AttributeImage()
+{
+}
--- /dev/null
+// Copyright (C) 2014-2021 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 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
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef ModelAPI_AttributeImage_H_
+#define ModelAPI_AttributeImage_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+#include <list>
+
+
+/**\class ModelAPI_AttributeImage
+ * \ingroup DataModel
+ * \brief API for the attribute that contains binary data.
+ * Used for images storage for an example. By default size is one, zero-based.
+ */
+
+class ModelAPI_AttributeImage : public ModelAPI_Attribute
+{
+ public:
+ /// Defines the value of the image attribute
+ MODELAPI_EXPORT virtual void setTexture(const int theWidth,
+ const int theHeight,
+ const std::list<unsigned char>& theByteArray,
+ const std::string& theFormat,
+ const bool sendUpdated = true) = 0;
+
+ /// Returns true, if texture width and height are non-zero
+ MODELAPI_EXPORT virtual bool hasTexture() = 0;
+
+ /// Returns the value of the image attribute
+ MODELAPI_EXPORT virtual bool texture(int& theWidth,
+ int& theHeight,
+ std::list<unsigned char>& theByteArray,
+ std::string& theFormat) = 0;
+
+ /// Copy the image data to the destination attribute
+ virtual void copyTo(std::shared_ptr<ModelAPI_AttributeImage> theTarget) const = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string typeId()
+ {
+ return "Image";
+ }
+
+ /// Returns the type of this class of attributes, not static method
+ MODELAPI_EXPORT virtual std::string attributeType();
+
+ /// To virtually destroy the fields of successors
+ MODELAPI_EXPORT virtual ~ModelAPI_AttributeImage();
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeImage();
+};
+
+//! Pointer on image attribute
+typedef std::shared_ptr<ModelAPI_AttributeImage> AttributeImagePtr;
+
+#endif
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeSelectionList;
class ModelAPI_AttributeIntArray;
+class ModelAPI_AttributeImage;
class ModelAPI_AttributeTables;
class ModelAPI_Object;
class GeomAPI_Shape;
virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
/// Returns the attribute that contains string values array
virtual std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID) = 0;
+ /// Returns the attribute that contains image
+ virtual std::shared_ptr<ModelAPI_AttributeImage> image(const std::string& theID) = 0;
/// Returns the attribute that contains tables
virtual std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID) = 0;
{
std::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
std::shared_ptr<ModelAPI_Document> myDoc; ///< document this object belongs to
- std::string textureFile = "";
public:
#ifdef DEBUG_NAMES
std::wstring myName; // name of this object
/// signal.
MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
- MODELAPI_EXPORT bool hasTextureFile()
+ MODELAPI_EXPORT virtual bool hasTexture()
{
- return (textureFile != "");
- }
-
- MODELAPI_EXPORT virtual void setTextureFile(const std::string & theTextureFile)
- {
- textureFile = theTextureFile;
- }
-
- MODELAPI_EXPORT const std::string & getTextureFile()
- {
- return textureFile;
+ return false;
}
protected:
public:
/// Reference to the color of the result.
- /// The integer array is used. It contains tree values for red green and blue values.
+ /// The integer array is used. It contains three values for red, green and blue values.
/// The values are in [0, 255] range
inline static const std::string& COLOR_ID()
{
public:
MODELAPI_EXPORT virtual ~ModelAPI_ResultBody();
+ /// Reference to the image attribute of the result body.
+ inline static const std::string& IMAGE_ID()
+ {
+ static const std::string MY_IMAGE_ID("Image");
+ return MY_IMAGE_ID;
+ }
+
/// Returns the group identifier of this result
MODELAPI_EXPORT virtual std::string groupName();
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeImage.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeBoolean.h>
#include <list>
}
}
+
+void copyImageAttribute (std::shared_ptr<ModelAPI_Result> theSource,
+ std::shared_ptr<ModelAPI_Result> theDest)
+{
+ if (!theSource.get() || !theDest.get())
+ return;
+
+ // images allowed only for ResultBody
+ ResultBodyPtr aSourceBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSource);
+ ResultBodyPtr aDestBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theDest);
+ if (!aSourceBody.get() || !aDestBody.get())
+ return;
+
+ AttributeImagePtr aSourceImage =
+ theSource->data()->image(ModelAPI_ResultBody::IMAGE_ID());
+ if (aSourceImage.get() && aSourceImage->hasTexture()) {
+ AttributeImagePtr aDestImage =
+ theDest->data()->image(ModelAPI_ResultBody::IMAGE_ID());
+ if (aDestImage.get()) {
+ aSourceImage->copyTo(aDestImage);
+ }
+ }
+}
+
std::list<FeaturePtr> referencedFeatures(
std::shared_ptr<ModelAPI_Result> theTarget, const std::string& theFeatureKind,
const bool theSortResults)
MODELAPI_EXPORT void copyVisualizationAttrs(std::shared_ptr<ModelAPI_Result> theSource,
std::shared_ptr<ModelAPI_Result> theDest);
+/*! Copies image attribute from one result to another.
+* \param theSource a result that contains the image data
+* \param theDest a destination result that takes the image data
+*/
+MODELAPI_EXPORT void copyImageAttribute(std::shared_ptr<ModelAPI_Result> theSource,
+ std::shared_ptr<ModelAPI_Result> theDest);
+
/*! Produces list of features that reference to the given target (directly or through sub-results)
* \param theTarget the referenced result
* \param theFeatureKind the resulting features filter: the feature kind or all for the empty string
isModified = true;
}
else {
- if (myFeature->firstResult().get() && myFeature->firstResult()->hasTextureFile())
- {
- PartSet_Module::setTexture( myFeature->firstResult()->getTextureFile(), aPresentation);
+ if (myFeature->firstResult().get()) {
+ PartSet_Module::setTexture(aPresentation, myFeature->firstResult());
}
anOperationPrs->Redisplay();
isModified = true;
#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeImage.h>
#include <ModelAPI_ResultGroup.h>
#include <GeomDataAPI_Point2D.h>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
#include <Graphic3d_Texture2Dmanual.hxx>
-#ifdef HAVE_SALOME
-#include <OCCViewer_Utilities.h>
-#endif
#define FEATURE_ITEM_COLOR "0,0,225"
return aTransparency;
}
+static AttributeImagePtr findImage(const ObjectPtr& theResult)
+{
+ AttributeImagePtr anImageAttr;
+
+ if (theResult.get()) {
+ ResultBodyPtr aResultBody =
+ std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (aResultBody.get()) {
+ anImageAttr = aResultBody->data()->image(ModelAPI_ResultBody::IMAGE_ID());
+ if (!anImageAttr.get() || !anImageAttr->hasTexture()) {
+ // try to find an image attribute in parents
+ ObjectPtr aParent = theResult->document()->parent(theResult);
+ anImageAttr = findImage(aParent);
+ }
+ }
+ }
+
+ return anImageAttr;
+}
+
//******************************************************
-void PartSet_Module::setTexture(const std::string & theTextureFile, const AISObjectPtr& thePrs)
+void PartSet_Module::setTexture(const AISObjectPtr& thePrs,
+ const ResultPtr& theResult)
{
-#ifdef HAVE_SALOME
+ ResultBodyPtr aResultBody =
+ std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (!aResultBody.get())
+ return;
+
+ AttributeImagePtr anImageAttr = findImage(theResult);
+ if (!anImageAttr.get() || !anImageAttr->hasTexture())
+ return;
+
+ int aWidth, aHeight;
+ std::string aFormat;
+ std::list<unsigned char> aByteList;
+ anImageAttr->texture(aWidth, aHeight, aByteList, aFormat);
+
Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
- if (!anAIS.IsNull())
- {
+ if (!anAIS.IsNull()) {
/// set color to white and change material aspect,
/// in order to keep a natural apect of the image.
thePrs->setColor(255, 255, 255);
myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(aMatAspect);
- Handle(Image_PixMap) aPixmap;
- QPixmap px(theTextureFile.c_str());
-
- if (!px.isNull() )
- aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
+ //aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage());
+ Handle(Image_PixMap) aPixmap = new Image_PixMap();
+ aPixmap->InitTrash(Image_PixMap::ImgBGRA, aWidth, aHeight);
+ std::list<unsigned char>::iterator aByteIter = aByteList.begin();
+ for (int aLine = 0; aLine < aHeight; ++aLine) {
+ // convert pixels from ARGB to renderer-compatible RGBA
+ for (int aByte = 0; aByte < aWidth; ++aByte) {
+ Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
+
+ aPixmapBytes.b() = (Standard_Byte) *aByteIter++;
+ aPixmapBytes.g() = (Standard_Byte) *aByteIter++;
+ aPixmapBytes.r() = (Standard_Byte) *aByteIter++;
+ aPixmapBytes.a() = (Standard_Byte) *aByteIter++;
+ }
+ }
anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
(new Graphic3d_Texture2Dmanual(aPixmap));
anAISShape->SetDisplayMode(AIS_Shaded);
}
}
-#endif
}
//******************************************************
thePrs->setDeflection(getResultDeflection(aResult));
thePrs->setTransparency(getResultTransparency(aResult));
- /// set texture parameters
- if(aResult->hasTextureFile()) {
- setTexture(aResult->getTextureFile(), thePrs);
- }
+ /// set texture parameters, if any
+ setTexture(thePrs, aResult);
}
if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) {
thePrs->setWidth(2);
virtual void createFeatures();
/// add texture
- static void setTexture(const std::string &theTextureFile, const AISObjectPtr& thePrs);
+ static void setTexture(const AISObjectPtr& thePrs, const ResultPtr& theResult);
public slots:
/// Slolt called on object display