Ejemplo n.º 1
0
void QValueDlg::onSetColor(QString sName)
{
    if("mBackRect" == sName)
    {
        QColor mColor(0,0,0);
        QString scolor = pwnd->ColorTOString(mColor);
        pQvalueColor->onGetValueBackColor(mColor);
        QString nColor = pwnd->ColorTOString(mColor);
        pBaseItem->SetPropertyValue("mBackRect.BackColor",QVariant(nColor));
    }
    else if("mFramRect" == sName)
    {
        QColor mColor(0,0,0);
        QString scolor = pwnd->ColorTOString(mColor);
        pQvalueColor->onGetValueColor(mColor);
        QString nColor = pwnd->ColorTOString(mColor);
        pBaseItem->SetPropertyValue("mFramRect.BackColor",QVariant(nColor));
    }
}
/* static */
bool
UsdMayaTranslatorMesh::_AssignColorSetPrimvarToMesh(
        const UsdGeomMesh& primSchema,
        const UsdGeomPrimvar& primvar,
        MFnMesh& meshFn)
{
    const TfToken& primvarName = primvar.GetPrimvarName();
    const SdfValueTypeName& typeName = primvar.GetTypeName();

    MString colorSetName(primvarName.GetText());

    // If the primvar is displayOpacity and it is a FloatArray, check if
    // displayColor is authored. If not, we'll import this 'displayOpacity'
    // primvar as a 'displayColor' color set. This supports cases where the
    // user created a single channel value for displayColor.
    // Note that if BOTH displayColor and displayOpacity are authored, they will
    // be imported as separate color sets. We do not attempt to combine them
    // into a single color set.
    if (primvarName == UsdMayaMeshColorSetTokens->DisplayOpacityColorSetName &&
            typeName == SdfValueTypeNames->FloatArray) {
        if (!UsdMayaRoundTripUtil::IsAttributeUserAuthored(primSchema.GetDisplayColorPrimvar())) {
            colorSetName = UsdMayaMeshColorSetTokens->DisplayColorColorSetName.GetText();
        }
    }

    // We'll need to convert colors from linear to display if this color set is
    // for display colors.
    const bool isDisplayColor =
        (colorSetName == UsdMayaMeshColorSetTokens->DisplayColorColorSetName.GetText());

    // Get the raw data before applying any indexing. We'll only populate one
    // of these arrays based on the primvar's typeName, and we'll also set the
    // color representation so we know which array to use later.
    VtFloatArray alphaArray;
    VtVec3fArray rgbArray;
    VtVec4fArray rgbaArray;
    MFnMesh::MColorRepresentation colorRep;
    size_t numValues = 0;

    MStatus status = MS::kSuccess;

    if (typeName == SdfValueTypeNames->FloatArray) {
        colorRep = MFnMesh::kAlpha;
        if (!primvar.Get(&alphaArray) || alphaArray.empty()) {
            status = MS::kFailure;
        } else {
            numValues = alphaArray.size();
        }
    } else if (typeName == SdfValueTypeNames->Float3Array ||
               typeName == SdfValueTypeNames->Color3fArray) {
        colorRep = MFnMesh::kRGB;
        if (!primvar.Get(&rgbArray) || rgbArray.empty()) {
            status = MS::kFailure;
        } else {
            numValues = rgbArray.size();
        }
    } else if (typeName == SdfValueTypeNames->Float4Array ||
               typeName == SdfValueTypeNames->Color4fArray) {
        colorRep = MFnMesh::kRGBA;
        if (!primvar.Get(&rgbaArray) || rgbaArray.empty()) {
            status = MS::kFailure;
        } else {
            numValues = rgbaArray.size();
        }
    } else {
        TF_WARN("Unsupported color set primvar type '%s' for primvar '%s' on "
                "mesh: %s",
                typeName.GetAsToken().GetText(),
                primvarName.GetText(),
                primvar.GetAttr().GetPrimPath().GetText());
        return false;
    }

    if (status != MS::kSuccess || numValues == 0) {
        TF_WARN("Could not read color set values from primvar '%s' on mesh: %s",
                primvarName.GetText(),
                primvar.GetAttr().GetPrimPath().GetText());
        return false;
    }

    VtIntArray assignmentIndices;
    int unauthoredValuesIndex = -1;
    if (primvar.GetIndices(&assignmentIndices)) {
        // The primvar IS indexed, so the indices array is what determines the
        // number of color values.
        numValues = assignmentIndices.size();
        unauthoredValuesIndex = primvar.GetUnauthoredValuesIndex();
    }

    // Go through the color data and translate the values into MColors in the
    // colorArray, taking into consideration that indexed data may have been
    // authored sparsely. If the assignmentIndices array is empty then the data
    // is NOT indexed.
    // Note that with indexed data, the data is added to the arrays in ascending
    // component ID order according to the primvar's interpolation (ascending
    // face ID for uniform interpolation, ascending vertex ID for vertex
    // interpolation, etc.). This ordering may be different from the way the
    // values are ordered in the primvar. Because of this, we recycle the
    // assignmentIndices array as we go to store the new mapping from component
    // index to color index.
    MColorArray colorArray;
    for (size_t i = 0; i < numValues; ++i) {
        int valueIndex = i;

        if (i < assignmentIndices.size()) {
            // The data is indexed, so consult the indices array for the
            // correct index into the data.
            valueIndex = assignmentIndices[i];

            if (valueIndex == unauthoredValuesIndex) {
                // This component is unauthored, so just update the
                // mapping in assignmentIndices and then skip the value.
                // We don't actually use the value at the unassigned index.
                assignmentIndices[i] = -1;
                continue;
            }

            // We'll be appending a new value, so the current length of the
            // array gives us the new value's index.
            assignmentIndices[i] = colorArray.length();
        }

        GfVec4f colorValue(1.0);

        switch(colorRep) {
            case MFnMesh::kAlpha:
                colorValue[3] = alphaArray[valueIndex];
                break;
            case MFnMesh::kRGB:
                colorValue[0] = rgbArray[valueIndex][0];
                colorValue[1] = rgbArray[valueIndex][1];
                colorValue[2] = rgbArray[valueIndex][2];
                break;
            case MFnMesh::kRGBA:
                colorValue[0] = rgbaArray[valueIndex][0];
                colorValue[1] = rgbaArray[valueIndex][1];
                colorValue[2] = rgbaArray[valueIndex][2];
                colorValue[3] = rgbaArray[valueIndex][3];
                break;
            default:
                break;
        }

        if (isDisplayColor) {
            colorValue = UsdMayaColorSpace::ConvertLinearToMaya(colorValue);
        }

        MColor mColor(colorValue[0], colorValue[1], colorValue[2], colorValue[3]);
        colorArray.append(mColor);
    }

    // colorArray now stores all of the values and any unassigned components
    // have had their indices set to -1, so update the unauthored values index.
    unauthoredValuesIndex = -1;

    const bool clamped = UsdMayaRoundTripUtil::IsPrimvarClamped(primvar);

    status = meshFn.createColorSet(colorSetName, nullptr, clamped, colorRep);
    if (status != MS::kSuccess) {
        TF_WARN("Unable to create color set '%s' for mesh: %s",
                colorSetName.asChar(),
                meshFn.fullPathName().asChar());
        return false;
    }

    // Create colors on the mesh from the values we collected out of the
    // primvar. We'll assign mesh components to these values below.
    status = meshFn.setColors(colorArray, &colorSetName, colorRep);
    if (status != MS::kSuccess) {
        TF_WARN("Unable to set color data on color set '%s' for mesh: %s",
                colorSetName.asChar(),
                meshFn.fullPathName().asChar());
        return false;
    }

    const TfToken& interpolation = primvar.GetInterpolation();

    // Build an array of value assignments for each face vertex in the mesh.
    // Any assignments left as -1 will not be assigned a value.
    MIntArray colorIds = _GetMayaFaceVertexAssignmentIds(meshFn,
                                                         interpolation,
                                                         assignmentIndices,
                                                         unauthoredValuesIndex);

    status = meshFn.assignColors(colorIds, &colorSetName);
    if (status != MS::kSuccess) {
        TF_WARN("Could not assign color values to color set '%s' on mesh: %s",
                colorSetName.asChar(),
                meshFn.fullPathName().asChar());
        return false;
    }

    return true;
}
Ejemplo n.º 3
0
void QValueDlg::onDrawSence(QString sName)
{
    QString sText = "";
    QColor mColor(0,0,0);
    if(bInitFlag)//初始化完成后调用就是重画设置属性
    {
        if("FontColor" == sName)
        {
            pQvalueColor->onGetValueColor(mColor);
            pCopyItem->SetFontColor(mColor);
            //pBaseItem->SetPropertyValue("mText.FontColor",QVariant(nColor));
        }
        else if("BackColor" == sName)
        {
            pQvalueColor->onGetValueBackColor(mColor);
            pCopyItem->SetRectBackColor(mColor);
            //pBaseItem->SetPropertyValue("mBackRect.BackColor",QVariant(nColor));
        }
        else if("Text" == sName)
        {
            if(DATAINPUTSHOW == eDataType)
            {
                sText.clear();
                int nTotaldigit = pQvalueShow->onGetTotaldigit();
                for(int i = 0; i < nTotaldigit;i++)
                {
                    sText = sText + "8";
                }
                int nPoint = pQvalueShow->onGetDecimaldigit();
                if(nPoint > 0 && nPoint < nTotaldigit)
                {
                    sText.insert(nTotaldigit - nPoint,'.');
                }
                int nfontsize = pQvalueShow->onGetFontSize();
                QString sFont = pQvalueShow->onGetFont(eDataType);
                pBaseItem->SetPropertyValue("mText.Font",QVariant(sFont));
                pBaseItem->SetPropertyValue("mText.FontSize",QVariant(nfontsize));
            }
            else if(ASCIIINPUTSHOW == eDataType)
            {
                for(int i = 0; i <pQvalueShow->onGetTotaldigit(); i++)
                {
                    int nChar = i%26;
                    sText.insert(i,'A'+nChar);
                }
                int nfontsize = pQvalueShow->onGetFontSize();
                QString sFont = pQvalueShow->onGetFont(eDataType);
                pBaseItem->SetPropertyValue("mText.Font",QVariant(sFont));
                pBaseItem->SetPropertyValue("mText.FontSize",QVariant(nfontsize));
            }
            else if(DATETIMEINPUT == eDataType)
            {
                sText = pQvalueBace->onGetpreText();
                pCopyItem->SetTextAlign(5);
                QString sFont = pQvalueBace->onGetFontType();
                pBaseItem->SetPropertyValue("mText.Font",QVariant(sFont));
                int nfontsize = pQvalueBace->onGetFontSize();
                pBaseItem->SetPropertyValue("mText.FontSize",QVariant(nfontsize));
                //pBaseItem->SetPropertyValue("mText.Alignment",QVariant(5)); //居中对齐
            }
            pCopyItem->SetText(sText);
            //pBaseItem->SetPropertyValue("mText.Text",QVariant(sText));
        }
        else if("4" == sName)
        {
            if(pCopyItem)
            {
                pCopyItem->SetTextAlign(4);
            }
//            pBaseItem->SetPropertyValue("mText.Alignment",QVariant(4)); //左对齐
//            data_st.eShowStyle = LStart;
//            ascii_st.nShowStyle = LStart;
//            time_st.nShowStyle = LStart;
        }
        else if("5" == sName)
        {
            if(pCopyItem)
            {
                pCopyItem->SetTextAlign(5);
            }
//            pBaseItem->SetPropertyValue("mText.Alignment",QVariant(5)); //居中对齐
//            data_st.eShowStyle = CStart;
//            ascii_st.nShowStyle = CStart;
//            time_st.nShowStyle = CStart;
        }
        else if("6" == sName)
        {
            if(pCopyItem)
            {
                pCopyItem->SetTextAlign(6);
            }
//            pBaseItem->SetPropertyValue("mText.Alignment",QVariant(6)); //右对齐
//            data_st.eShowStyle = RStart;
//            ascii_st.nShowStyle = RStart;
//            time_st.nShowStyle = RStart;
        }
        else if("Font" == sName)
        {
            QString sFont = "";
            if(DATAINPUTSHOW == eDataType || ASCIIINPUTSHOW == eDataType)
            {
                sFont = pQvalueShow->onGetFont(eDataType);
            }
            else
            {
                sFont = pQvalueBace->onGetFontType();
            }
            pBaseItem->SetPropertyValue("mText.Font",QVariant(sFont));
        }
        else if("FontSize" == sName)
        {
            int nfontsize = 10;
            if(DATAINPUTSHOW == eDataType || ASCIIINPUTSHOW == eDataType)
            {
                nfontsize = pQvalueShow->onGetFontSize();
            }
            else
            {
                nfontsize = pQvalueBace->onGetFontSize();
            }
            pBaseItem->SetPropertyValue("mText.FontSize",QVariant(nfontsize));
        }
        else if("FontType" == sName)
        {
            onSetFontType();
        }
    }
    else
    {
        if("" != sName)
        {
            return;//非初始化进入直接返回
        }
        DataDisplayItem *pGroupItem = new DataDisplayItem;
        QRectItem *pBackRect;
        QRectItem *pFramRect;
        QSimpleTextItem *pTextRect;

        QRectF brect(QPointF(5,5), QSize(90,90));
        pBackRect = new QRectItem(brect);
        pQvalueColor->onGetValueBackColor(mColor);
        pBackRect->SetBackColor(mColor);
        pBackRect->SetLineType(0);
        pBackRect->setZValue(2);
        pBackRect->SetName(tr("mBackRect"));
        pBackRect->setFlag(QGraphicsItem::ItemIsSelectable, false);
        pBackRect->setFlag(QGraphicsItem::ItemIsMovable, false);

        QRectF frect(QPointF(0,0), QSize(100,100));
        pFramRect = new QRectItem(frect);
        pFramRect->SetBackColor(QColor(224,224,224));
        pFramRect->SetLineType(0);
        pFramRect->setZValue(1);
        pFramRect->SetName(tr("mFramRect"));
        pFramRect->setFlag(QGraphicsItem::ItemIsSelectable, false);
        pFramRect->setFlag(QGraphicsItem::ItemIsMovable, false);
        pFramRect->SetPattern(0);

        QRectF mrect(QPointF(15,25), QSize(70,50));
        pTextRect = new QSimpleTextItem(mrect,"");
        pTextRect->SetName("mText");
        pTextRect->SetRectOutLine(false);
        pTextRect->setZValue(3);
        pTextRect->setFlag(QGraphicsItem::ItemIsSelectable, false);
        pTextRect->SetPattern(1);
        pTextRect->SetFontSize(pQvalueShow->onGetFontSize());
        int nTotaldigit = pQvalueShow->onGetTotaldigit();
        for(int i = 0; i < nTotaldigit;i++)
        {
            sText = sText + "8";
        }
        int nPoint = pQvalueShow->onGetDecimaldigit();
        if(nPoint > 0 && nPoint < nTotaldigit)
        {
            sText.insert(nTotaldigit - nPoint,'.');
        }
        pTextRect->SetText(sText);
        pQvalueColor->onGetValueColor(mColor);
        pTextRect->SetFontColor(mColor);
        pQvalueColor->onGetValueBackColor(mColor);
        pTextRect->SetRectBackColor(mColor);

        QString sFont = pQvalueShow->onGetFont(eDataType);
        pTextRect->SetFontName(sFont);
        //pGroupItem->addToGroup(pFramRect);
        //pGroupItem->addToGroup(pBackRect);
        pGroupItem->addToGroup(pTextRect);

        pCopyItem = pGroupItem;
        pCopyItem->textItem = pTextRect;
        pScene->clear();
        pScene->addItem(pCopyItem);
        pBaseItem = new QGroupItem(pCopyItem);
        //pBaseItem->SetHeigth(100);
        //pBaseItem->SetWidth(100);
    }
    setTransparent();
}