#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeImage.h>
#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultParameter.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);
} else if (aObject->document() == aMgr->activeDocument()) {
if (hasParameter || hasFeature) {
- myMenuMgr->action("EDIT_CMD")->setEnabled(true);
- theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
- if (aCurrentOp && aFeature.get()) {
- if (aCurrentOp->id().toStdString() == aFeature->getKind())
+
+ // disable Edit menu for groups under ImportResult feature
+ bool isEnabled = true;
+ if (aFeature.get() && aFeature->getKind() == "Group")
+ {
+ std::shared_ptr<ModelAPI_CompositeFeature> anOwner =
+ ModelAPI_Tools::compositeOwner (aFeature);
+
+ if (anOwner.get() && anOwner->getKind() == "ImportResult")
+ {
myMenuMgr->action("EDIT_CMD")->setEnabled(false);
+ isEnabled = false;
+ }
+ }
+
+ if (isEnabled)
+ {
+ myMenuMgr->action("EDIT_CMD")->setEnabled(true);
+ theMenu->addAction(myMenuMgr->action("EDIT_CMD"));
+ if (aCurrentOp && aFeature.get()) {
+ if (aCurrentOp->id().toStdString() == aFeature->getKind())
+ myMenuMgr->action("EDIT_CMD")->setEnabled(false);
+ }
}
}
}