コード例 #1
0
QString CPPCodeClassField::getInitialValue() {

    if (parentIsAttribute())
    {
        UMLAttribute * at = dynamic_cast<UMLAttribute*>( getParentObject() );
        if (at) {
            return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
        } else {
            kError() << "CPPCodeClassField::getInitialValue: parent object is not a UMLAttribute"
            << endl;
            return "";
        }
    }
    else
    {
        if(fieldIsSingleValue()) {
            // FIX : IF the multiplicity is "1" then we should init a new object here, if its 0 or 1,
            //       then we can just return 'empty' string (minor problem).
            return "";
        } else {
            return " new "+getListFieldClassName()+"( )";
        }
    }

}
コード例 #2
0
/*
 * setValue calls onValueChange which will determine how
 * the value is handled. If the value VALUE_MODIFY_IGNORE
 * is returned, the value is silently discarded without
 * changing the value of the JavaScript object. This is
 * useful in the case where the value has already been changed
 * by calling forceSetValue in the overridden onValueChange.
 */
VALUE_MODIFY TiObject::setValue(Handle<Value> value)
{
	clearValue();
    VALUE_MODIFY modify = onValueChange(value_, value);
    if (modify != VALUE_MODIFY_ALLOW)
    {
        if (modify == VALUE_MODIFY_IGNORE)
        {
            modify = VALUE_MODIFY_ALLOW;
        }
        return modify;
    }
    TiObject* parent = getParentObject();
    if (parent != NULL)
    {
        modify = parent->onChildValueChange(this, value_, value);
        parent->release();
        if (modify != VALUE_MODIFY_ALLOW)
        {
            if (modify == VALUE_MODIFY_IGNORE)
            {
                modify = VALUE_MODIFY_ALLOW;
            }
            return modify;
        }
    }
    value_ = Persistent<Value>::New(value);
    return modify;
}
コード例 #3
0
void CodeClassFieldDeclarationBlock::syncToParent ()
{
    // for role-based accessors, we DON'T write ourselves out when
    // the name of the role is not defined.
    if (!(getParentClassField()->parentIsAttribute()))
    {
        UMLRole * parent = getParentObject()->asUMLRole();
        if (parent == 0)
            return;
        if (parent->name().isEmpty())
        {
            getComment()->setWriteOutText(false);
            setWriteOutText(false);
        } else {
            getComment()->setWriteOutText(true);
            setWriteOutText(true);
        }
    }

    // only update IF we are NOT AutoGenerated
    if (contentType() != AutoGenerated)
        return;

    updateContent();
}
コード例 #4
0
QString CPPCodeClassField::getFieldName() {
    if (parentIsAttribute())
    {
        UMLAttribute * at = (UMLAttribute*) getParentObject();
        return cleanName(at->getName());
    }
    else
    {
        UMLRole * role = (UMLRole*) getParentObject();
        QString roleName = role->getName();
        if(fieldIsSingleValue()) {
            return roleName.replace(0, 1, roleName.left(1).lower());
        } else {
            return roleName.lower() + "Vector";
        }
    }
}
コード例 #5
0
ファイル: rubycodeclassfield.cpp プロジェクト: KDE/umbrello
QString RubyCodeClassField::getFieldName()
{
    if (parentIsAttribute())
    {
        UMLAttribute * at = (UMLAttribute*) getParentObject();
        return cleanName(at->name());
    }
    else
    {
        UMLRole * role = (UMLRole*) getParentObject();
        QString roleName = role->name();
        if(fieldIsSingleValue()) {
            return roleName.replace(0, 1, roleName.left(1).toLower());
        } else {
            return roleName.toLower() + QLatin1String("Array");
        }
    }
}
コード例 #6
0
ファイル: codeparameter.cpp プロジェクト: Elv13/Umbrello-ng
void CodeParameter::initFields ( ClassifierCodeDocument * doc, UMLObject * obj) 
{
    m_parentObject = obj;

    m_parentDocument = doc;
    m_initialValue.clear();

    m_comment = CodeGenFactory::newCodeComment(m_parentDocument);
    m_comment->setText(getParentObject()->doc());

    connect(m_parentObject,SIGNAL(modified()),this,SLOT(syncToParent()));
}
コード例 #7
0
/**
 * set attributes of the node that represents this class
 * in the XMI document.
 */
void OwnedHierarchicalCodeBlock::setAttributesOnNode(QDomDocument & doc, QDomElement & elem)
{
    // set super-class attributes
    HierarchicalCodeBlock::setAttributesOnNode(doc, elem);
    OwnedCodeBlock::setAttributesOnNode(doc, elem);

    // set local class attributes
    elem.setAttribute("parent_id",ID2STR(getParentObject()->id()));

    // setting ID's takes special treatment
    // as UMLRoles arent properly stored in the XMI right now.
    // (change would break the XMI format..save for big version change )
    UMLRole * role = dynamic_cast<UMLRole*>(getParentObject());
    if(role) {
        // see comment on role_id at OwnedCodeBlock::setAttributesOnNode()
        elem.setAttribute("role_id", (role->role() == Uml::A));
    }
    /* else
            elem.setAttribute("role_id","-1");
    */
}
コード例 #8
0
ファイル: Plot3DDecomposer.cpp プロジェクト: ScilabOrg/scilab
/*
 * To do: compute and return color indices instead of directly looking
 * up colors from the colormap.
 */
void Plot3DDecomposer::fillColors(int id, float* buffer, int bufferLength, int elementsSize)
{
    int parentFigure = 0;
    int* pparentFigure = &parentFigure;
    int parent = 0;
    int* pparent = &parent;

    double* z = NULL;
    double* colormap = NULL;


    int numX = 0;
    int* piNumX = &numX;
    int numY = 0;
    int* piNumY = &numY;
    int colormapSize = 0;
    int* piColormapSize = &colormapSize;

    Plot3DDecomposer* decomposer = get();

    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piNumX);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piNumY);

    getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &z);

    parent = getParentObject(id);

    /* Temporary: to avoid getting a null parent_figure property when the object is built */
    if (parent == 0)
    {
        return;
    }

    getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_int, (void**) &pparentFigure);

    if (parentFigure == 0)
    {
        return;
    }

    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);

    decomposer->fillNormalizedZGridColors(buffer, bufferLength, elementsSize, colormap, colormapSize, z, numX, numY);

    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
}
コード例 #9
0
/*--------------------------------------------------------------------------*/
int sci_drawlater(char * fname, void* pvApiCtx)
{
    int iFalse =  (int)FALSE;
    int iParentFigureUID = 0;
    int* piParentFigureUID = &iParentFigureUID;
    int iSubwinUID = 0;
    int iCurChildUID = 0;
    int iType = -1;
    int *piType = &iType;

    CheckInputArgument(pvApiCtx, 0, 0);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if (nbInputArgument(pvApiCtx) <= 0)
    {
        iSubwinUID = getOrCreateDefaultSubwin();
        if (iSubwinUID != 0)
        {
            // Look for top level figure
            iCurChildUID = iSubwinUID;
            do
            {
                iParentFigureUID = getParentObject(iCurChildUID);
                getGraphicObjectProperty(iParentFigureUID, __GO_TYPE__, jni_int, (void **)&piType);
                iCurChildUID = iParentFigureUID;
            }
            while (iParentFigureUID != 0 && iType != __GO_FIGURE__);

            if (iParentFigureUID != 0)
            {
                setGraphicObjectProperty(iParentFigureUID, __GO_IMMEDIATE_DRAWING__, &iFalse, jni_bool, 1);
            }
        }
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
コード例 #10
0
QString JavaCodeClassField::getInitialValue()
{
    if (parentIsAttribute())
    {
        UMLAttribute * at = dynamic_cast<UMLAttribute*>(getParentObject());
        if (at) {
            return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
        } else {
            uError() << "parent object is not a UMLAttribute";
            return QString();
        }
    }
    else
    {
        if(fieldIsSingleValue()) {
            // FIX : IF the multiplicity is "1" then we should init a new object here, if its 0 or 1,
            //       then we can just return 'empty' string (minor problem).
            return QString();
        } else {
            return QLatin1String(" new ") + JavaCodeGenerator::getListFieldClassName() + QLatin1String("()");
        }
    }
}
コード例 #11
0
void MeshFecDataDecomposer::fillColors(int id, float* buffer, int bufferLength, int elementsSize)
{
    int parent = 0;
    int parentFigure = 0;
    int * piParentFigure = &parentFigure;

    double* values = NULL;
    double* zBounds = NULL;
    double* colormap = NULL;

    double minValue = 0.;
    double maxValue = 0.;
    double valueRange = 0.;

    float minColor[3];
    float maxColor[3];

    int colormapSize = 0;
    int* piColormapSize = &colormapSize;

    int numVertices = 0;
    int* piNumVertices = &numVertices;

    int minColorIndex = 0;
    int maxColorIndex = 0;

    int* colorRange = NULL;
    int useOutsideColors = 0;
    int bufferOffset = 0;

    parent = getParentObject(id);

    /* Temporary: to avoid getting a null parent_figure property when the object is built */
    if (parent == 0)
    {
        return;
    }

    getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_int, (void**) &piParentFigure);

    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);

    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES__, jni_int, (void**) &piNumVertices);

    getGraphicObjectProperty(id, __GO_DATA_MODEL_VALUES__, jni_double_vector, (void**) &values);

    getGraphicObjectProperty(id, __GO_Z_BOUNDS__, jni_double_vector, (void**) &zBounds);
    getGraphicObjectProperty(id, __GO_COLOR_RANGE__, jni_int_vector, (void**) &colorRange);

    if (colorRange[0] != 0 || colorRange[1] != 0)
    {
        /* To do: use a scilab index to colormap index conversion function */
        minColorIndex = colorRange[0] - 1;
        maxColorIndex = colorRange[1] - 1;

        if (minColorIndex < 0)
        {
            minColorIndex = 0;
        }
        if (maxColorIndex < 0)
        {
            maxColorIndex = 0;
        }

        if (maxColorIndex > colormapSize - 1)
        {
            maxColorIndex = colormapSize - 1;
        }
        if (minColorIndex > colormapSize - 1)
        {
            minColorIndex = colormapSize - 1;
        }

    }
    else
    {
        minColorIndex = 0;
        maxColorIndex = colormapSize - 1;
    }

    releaseGraphicObjectProperty(__GO_COLOR_RANGE__, colorRange, jni_int_vector, 0);

    computeMinMaxValues(values, numVertices, &minValue, &maxValue);

    /* Z-bounds are not taken into account if either of them is invalid */
    if ((zBounds[0] != 0.0 || zBounds[1] != 0.0) && (DecompositionUtils::isValid(zBounds[0]) && DecompositionUtils::isValid(zBounds[1])) && (zBounds[0] != zBounds[1]))
    {
        int* outsideColors;

        minValue = zBounds[0];
        maxValue = zBounds[1];

        getGraphicObjectProperty(id, __GO_OUTSIDE_COLOR__, jni_int_vector, (void**) &outsideColors);

        if (outsideColors[0] != 0 || outsideColors[1] != 0)
        {
            useOutsideColors = 1;

            ColorComputer::getDirectColor((double) outsideColors[0] - 1.0, colormap, colormapSize, minColor);
            ColorComputer::getDirectColor((double) outsideColors[1] - 1.0, colormap, colormapSize, maxColor);
        }
    }

    releaseGraphicObjectProperty(__GO_Z_BOUNDS__, zBounds, jni_double_vector, 0);

    /* To be verified (when reverse z bounds are specified) */
    if (DecompositionUtils::getAbsoluteValue(maxValue - minValue) < DecompositionUtils::getMinDoubleValue())
    {
        valueRange = 1.0;
    }
    else
    {
        valueRange = maxValue - minValue;
    }

    for (int i = 0; i < numVertices; i++)
    {
        bufferOffset = elementsSize * i;

        if (useOutsideColors == 1)
        {
            if (values[i] < minValue)
            {
                buffer[bufferOffset] = minColor[0];
                buffer[bufferOffset + 1] = minColor[1];
                buffer[bufferOffset + 2] = minColor[2];
            }
            else if (values[i] > maxValue)
            {
                buffer[bufferOffset] = maxColor[0];
                buffer[bufferOffset + 1] = maxColor[1];
                buffer[bufferOffset + 2] = maxColor[2];
            }
            else
            {
                /* To do: replace 0.5 by a macro-definition */
                ColorComputer::getColor(values[i], minValue, valueRange, 0.5, colormap, minColorIndex, maxColorIndex, colormapSize, &buffer[bufferOffset]);
            }
        }
        else
        {
            /* To do: replace 0.5 by a macro-definition */
            ColorComputer::getColor(values[i], minValue, valueRange, 0.5, colormap, minColorIndex, maxColorIndex, colormapSize, &buffer[bufferOffset]);
        }

        if (elementsSize == 4)
        {
            buffer[bufferOffset + 3] = 1.0;
        }
    }

    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
}
コード例 #12
0
/*------------------------------------------------------------------------*/
int set_current_axes_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    int iCurAxesUID = 0;
    int iCurChildUID = 0;
    int iParentFigureUID = -1;
    int* piParentFigureUID = &iParentFigureUID;
    int type = -1;
    int *piType = &type;

    if (iObjUID != 0)
    {
        /* This property should not be called on a handle */
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "current_axes");
        return SET_PROPERTY_ERROR;
    }

    if (valueType != sci_handles)
    {
        Scierror(999, _("Wrong type for '%s' property: Handle expected.\n"), "current_axes");
        return SET_PROPERTY_ERROR;
    }

    iCurAxesUID = getObjectFromHandle((long)((long long*)_pvData)[0]);

    if (iCurAxesUID == 0)
    {
        Scierror(999, _("Wrong value for '%s' property: Must be a valid handle.\n"), "current_entity");
        return SET_PROPERTY_ERROR;
    }

    getGraphicObjectProperty(iCurAxesUID, __GO_TYPE__, jni_int, (void **)&piType);

    if (type != __GO_AXES__)
    {
        Scierror(999, _("Wrong value for '%s' property: Must be a handle on axes.\n"), "current_axes");
        return SET_PROPERTY_ERROR;
    }

    setCurrentSubWin(iCurAxesUID);


    // Look for top level figure
    type = -1;
    iCurChildUID = iCurAxesUID;
    do {
        iParentFigureUID = getParentObject(iCurChildUID);
        getGraphicObjectProperty(iParentFigureUID, __GO_TYPE__, jni_int, (void **)&piType);
        iCurChildUID = iParentFigureUID;
    } while (iParentFigureUID != -1 && type != __GO_FIGURE__);

    /* The current Axes' parent Figure's selected child property must be updated */
    setGraphicObjectProperty(iParentFigureUID, __GO_SELECTED_CHILD__, &iCurAxesUID, jni_int, 1);

    /* F.Leray 11.02.05 : if the new selected subwin is not inside the current figure, */
    /* we must also set the current figure to the subwin's parent */
    if (!isCurrentFigure(iParentFigureUID))
    {
        setCurrentFigure(iParentFigureUID);
    }

    return SET_PROPERTY_SUCCEED;
}
コード例 #13
0
// we basically want to update the start text of this method
void CPPHeaderCodeAccessorMethod::updateMethodDeclaration()
{
    CodeClassField * parentField = getParentClassField();
    ClassifierCodeDocument * doc = parentField->getParentDocument();
    CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
    CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
    CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);

    bool isInlineMethod = policy->getAccessorsAreInline( );
    QString tag = policy->getDocToolTag( );

    QString vectorClassName = policy->getVectorClassName();
    QString fieldName = cppfield->getFieldName();
    QString fieldType = cppfield->getTypeName();
    QString objectType = cppfield->getListObjectType();
    if(objectType.isEmpty())
        objectType = fieldName;

    QString methodReturnType = "void";
    QString methodName; // "get"+cppdoc->capitalizeFirstLetter(fieldName);
    QString methodParams = QChar(' '); // "get"+cppdoc->capitalizeFirstLetter(fieldName);
    QString headerText;
    QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();

    switch(getType()) {
    case CodeAccessorMethod::ADD:
        methodName = "add_"+fieldType;
        methodReturnType = "void";
        methodParams = objectType+" value ";
        headerText = "Add a "+fieldName+" object to the "+fieldName+"List"+endLine+getParentObject()->doc()+endLine+tag+"return void";
        break;
    case CodeAccessorMethod::REMOVE:
        methodName = "remove_"+fieldType;
        methodParams = objectType+" value ";
        methodReturnType = "void";
        headerText = "Remove a "+fieldName+" object from the "+fieldName+"List"+endLine+getParentObject()->doc()+endLine+tag+"return void";
        break;
    case CodeAccessorMethod::LIST:
        methodName = "get_"+fieldType+"_list";
        methodReturnType = vectorClassName;
        headerText = "Get the "+fieldName+"List"+endLine+getParentObject()->doc()+endLine+tag+"return "+vectorClassName+"with list of objects";
        break;
    case CodeAccessorMethod::SET:
        methodName = "set_"+fieldName;
        methodParams = fieldType+" value ";
        methodReturnType = "void";
        headerText = "Set the value of "+fieldName+endLine+getParentObject()->doc()+endLine+tag+"param value the value of "+fieldName;
        break;
    case CodeAccessorMethod::GET:
    default:
        methodName = "get_"+fieldName;
        methodReturnType = fieldType;
        headerText = "Get the value of "+fieldName+endLine+getParentObject()->doc()+endLine+tag+"return the value of "+fieldName;
        break;
    }

    // set header
    CPPCodeDocumentation * header = new CPPCodeDocumentation(doc);
    if(!getParentObject()->doc().isEmpty())
        header->setText(headerText);
    setComment(header);

    // set start/end method text
    QString startText = methodReturnType + ' ' + methodName + " (" + methodParams +')';
    if (isInlineMethod)
        startText += " {";
    else
        startText += ';';
    QString endText = (isInlineMethod ? "}" : "");

    setStartMethodText(startText);
    setEndMethodText(endText);

    setOverallIndentationLevel(1);
}
コード例 #14
0
/*--------------------------------------------------------------------------*/
int sci_rotate_axes(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrstackPointer = NULL;
    long long* stackPointer = NULL;

    int nbRow = 0;
    int nbCol = 0;

    int iUID = 0;
    int* piUID = &iUID;
    int iType = -1;
    int *piType = &iType;

    /* check size of input and output */
    CheckInputArgument(pvApiCtx, 0, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if (nbInputArgument(pvApiCtx) == 0)
    {
        iUID = getCurrentFigure();
    }
    else
    {
        /* Get figure or subwin handle */
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Single Figure or Axes handle expected.\n"), fname, 1);
            return -1;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of handle at position 1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &nbRow, &nbCol, &stackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
            return 1;
        }


        if (nbRow * nbCol != 1)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Single Figure or Axes handle expected.\n"), fname, 1);
            return -1;
        }

        iUID = getObjectFromHandle((long int) * stackPointer);

        getGraphicObjectProperty(iUID, __GO_TYPE__, jni_int, (void **)&piType);
        if (iType == __GO_AXES__)
        {
            iUID = getParentObject(iUID);
        }
    }

    if (iUID == 0)
    {
        Scierror(999, _("%s: The handle is not or no more valid.\n"), fname);
        return -1;
    }

    setGraphicObjectProperty(iUID, __GO_INFO_MESSAGE__, "Right click and drag to rotate.", jni_string, 1);

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    return 0;
}
コード例 #15
0
void RubyCodeClassFieldDeclarationBlock::updateContent( )
{

    CodeClassField * cf = getParentClassField();
    ClassifierCodeDocument * doc = cf->getParentDocument();
    RubyCodeClassField * rcf = dynamic_cast<RubyCodeClassField*>(cf);
    RubyClassifierCodeDocument* rdoc = dynamic_cast<RubyClassifierCodeDocument*>(doc);
    CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy();
    CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAssociationFieldScope();

    // Set the comment
    QString notes = getParentObject()->getDoc();
    getComment()->setText(notes);

    // Set the body
    QString staticValue = getParentObject()->getStatic() ? "static " : "";
    QString scopeStr = rdoc->scopeToRubyDecl(getParentObject()->getVisibility());

    // IF this is from an association, then scope taken as appropriate to policy
    if(!rcf->parentIsAttribute())
    {
        switch (scopePolicy) {
        case CodeGenerationPolicy::Public:
        case CodeGenerationPolicy::Private:
        case CodeGenerationPolicy::Protected:
            scopeStr = rdoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy);
            break;
        default:
        case CodeGenerationPolicy::FromParent:
            // do nothing here... will leave as from parent object
            break;
        }
    }

    QString typeName = rcf->getTypeName();
    QString fieldName = rcf->getFieldName();
    QString initialV = rcf->getInitialValue();

    if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue())
        typeName = "Array";

    QString body = staticValue+scopeStr+' '+typeName+' '+fieldName;
    if (!initialV.isEmpty())
        body.append(" = " + initialV);
    else if (!cf->parentIsAttribute())
    {
        UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject());
        if (role->getObject()->getBaseType() == Uml::ot_Interface)
        {
            // do nothing.. can't instanciate an interface
        } else {

            // FIX?: IF a constructor method exists in the classifiercodedoc
            // of the parent Object, then we can use that instead (if its empty).
            if(cf->fieldIsSingleValue())
            {
                if(!typeName.isEmpty())
                    body.append(" = " + typeName + ".new()");
            } else
                body.append(" = []");
        }
    }

    setText(body);

}
コード例 #16
0
ファイル: sci_glue.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
int sci_glue(char * fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    long long* l1 = NULL;
    double* l2 = NULL;
    int* lind = NULL;
    long long* outindex = NULL;

    int numrow = 0, numcol = 0, n = 0, cx1 = 1;
    int *pObj = NULL;
    int i = 0;

    int iCompoundUID = 0;
    int iParentUID = 0;
    int iCurrentParentUID = 0;
    int* piCurrentParentUID = &iCurrentParentUID;
    int iObjUID = 0;

    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /*  set or create a graphic window */
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of handle at position 1.
    sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &numrow, &numcol, &l1); /* We get the scalar value if it is ones */
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
        return 1;
    }

    n = numrow * numcol;
    sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, numrow, numcol, &l2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, nbInputArgument(pvApiCtx) + 2, numrow, numcol, &lind);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    if (n > 1)
    {
        C2F(dcopy)(&n, (double*)l1, &cx1, l2, &cx1);
        C2F(dsort)(l2, &n, (int*)(lind));
        for (i = 1; i < n; i++)
        {
            long long i1 = ((long long*)l2)[i];
            long long i2 = ((long long*)l2)[i - 1];

            if (i1 == i2)
            {
                Scierror(999, _("%s: Each handle should not appear twice.\n"), fname);
                return 0;
            }
        }
    }

    /* we must change the pobj to the Compound type */
    pObj = (int*)MALLOC(n * sizeof(int));
    for (i = 0 ; i < n ; i++)
    {
        iObjUID = getObjectFromHandle((long)l1[i]);
        pObj[i] = iObjUID;
        if (iObjUID == 0)
        {
            FREE(pObj);
            Scierror(999, _("%s: The handle is not or no more valid.\n"), fname);
            return 0;
        }

        iCurrentParentUID = getParentObject(iObjUID);
        //getGraphicObjectProperty(iObjUID, __GO_PARENT__, jni_string, (void **)&piCurrentParentUID);
        if (i == 0)
        {
            iParentUID = iCurrentParentUID;
        }

        if (iParentUID != iCurrentParentUID)
        {
            FREE(pObj);
            Scierror(999, _("%s: Objects must have the same parent.\n"), fname);
            return 0;
        }

    }

    //ret = CheckForCompound (handelsvalue, n);
    //if (ret>0)
    //{
    // MEM LEAK
    //    Scierror(999,_("%s: Handle %d cannot be glued (invalid parent).\n"),fname,ret);
    //    return 0;
    //}

    //if (ret<0)
    //{
    // MEM LEAK
    //   Scierror(999,_("%s: Handle %d cannot be glued (invalid type).\n"),fname,-ret);
    //    return 0;
    //}

    iCompoundUID = createCompound(iParentUID, pObj, n);
    setCurrentObject(iCompoundUID);

    numrow = 1;
    numcol = 1;

    sciErr = allocMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 3, numrow, numcol, &outindex);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    outindex[0] = getHandle(iCompoundUID);
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 3;
    ReturnArguments(pvApiCtx);
    FREE(pObj);

    return 0;
}
コード例 #17
0
ファイル: codeparameter.cpp プロジェクト: Elv13/Umbrello-ng
/**
 * Create the string representation of this code parameter.
 * @return      QString
 */
void CodeParameter::syncToParent( )
{
    getComment()->setText(getParentObject()->doc());

    updateContent();
}
コード例 #18
0
ファイル: MBLookAt.cpp プロジェクト: galek/MIngEd
void MBLookAt::update(void)
{
	MEngine * engine = MEngine::getInstance();
	MLevel * level = engine->getLevel();
	MScene * scene = level->getCurrentScene();

	MObject3d * parent = getParentObject();

	const char * targetName = m_targetName.getData();
	if(strcmp(targetName, "none") == 0)
		return;

	// target object
	MObject3d * object = scene->getObjectByName(targetName);
	if(! object)
		return;

	// direction
	MVector3 direction = object->getTransformedPosition() - parent->getTransformedPosition();
	if(direction.x == 0 && direction.y == 0 && direction.z == 0)
		return;

	float angle;
	float roll;

	MVector3 axis;

	// compute initial roll
	MVector3 ZAxis = parent->getInverseRotatedVector(MVector3(0, 0, 1)).getNormalized();
	ZAxis.z = 0;
	ZAxis.normalize();

	if(ZAxis.x == 0 && ZAxis.y == 0)
	{
		MVector3 YAxis = parent->getInverseRotatedVector(MVector3(0, 1, 0)).getNormalized();
		YAxis.z = 0;
		YAxis.normalize();

		axis = MVector3(0, 1, 0).crossProduct(YAxis);
		roll = acosf(MVector3(0, 1, 0).dotProduct(YAxis));

		if(MVector3(0, 0, 1).dotProduct(axis) < 0)
			roll = -roll;
	}
	else
	{
		axis = MVector3(0, 1, 0).crossProduct(ZAxis);
		roll = acosf(MVector3(0, 1, 0).dotProduct(ZAxis));

		if(MVector3(0, 0, 1).dotProduct(axis) < 0)
			roll = -roll;
	}

	if(roll < 0.001f && roll > -0.001f) roll = 0;

	// look-at
	MVector3 cameraAxis = MVector3(0, 0, -1);

	axis = cameraAxis.crossProduct(direction);
	angle = acosf(cameraAxis.dotProduct(direction.getNormalized()));

	parent->setAxisAngleRotation(axis, (float)(angle * RAD_TO_DEG));
	parent->updateMatrix();

	// set roll
	ZAxis = parent->getInverseRotatedVector(MVector3(0, 0, 1)).getNormalized();;
	ZAxis.z = 0;
	ZAxis.normalize();

	if(ZAxis.x == 0 && ZAxis.y == 0)
	{
		parent->addAxisAngleRotation(MVector3(0, 0, 1), (float)(-roll*RAD_TO_DEG));
	}
	else
	{
		axis = MVector3(0, 1, 0).crossProduct(ZAxis);
		angle = acosf(MVector3(0, 1, 0).dotProduct(ZAxis));
		if(angle < 0.001f && angle > -0.001f) angle = 0;

		if(MVector3(0, 0, 1).dotProduct(axis) < 0)
			angle = -angle;

		parent->addAxisAngleRotation(MVector3(0, 0, 1), (float)((angle-roll)*RAD_TO_DEG));
	}

}
コード例 #19
0
// we basically want to update the start text of this method
void CPPSourceCodeAccessorMethod::updateMethodDeclaration()
{

    CodeClassField * parentField = getParentClassField();
    ClassifierCodeDocument * doc = parentField->getParentDocument();
    CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
    CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
    CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);
    UMLClassifier * c = doc->getParentClassifier();

    bool isInlineMethod = policy->getAccessorsAreInline( );

    QString vectorClassName = policy->getVectorClassName();
    QString fieldName = cppfield->getFieldName();
    QString fieldType = cppfield->getTypeName();
    QString objectType = cppfield->getListObjectType();
    if(objectType.isEmpty())
        objectType = fieldName;

    QString methodReturnType = "void";
    QString methodName;
    QString methodParams;
    QString headerText;
    QString className = CodeGenerator::cleanName(c->getName());
    QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();

    switch(getType()) {
    case CodeAccessorMethod::ADD:
        methodName = "add_"+fieldType;
        methodReturnType = "void";
        methodParams = objectType+" value ";
        headerText = "Add a "+fieldName+" object to the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void";
        break;
    case CodeAccessorMethod::REMOVE:
        methodName = "remove_"+fieldType;
        methodParams = objectType+" value ";
        methodReturnType = "void";
        headerText = "Remove a "+fieldName+" object from the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void";
        break;
    case CodeAccessorMethod::LIST:
        methodName = "get_"+fieldType+"_list";
        methodReturnType = vectorClassName;
        headerText = "Get the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return "+vectorClassName+"with list of objects";
        break;
    case CodeAccessorMethod::SET:
        methodName = "set_"+fieldName;
        methodParams = fieldType+" value ";
        methodReturnType = "void";
        headerText = "Set the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@param value the value of "+fieldName;
        break;
    case CodeAccessorMethod::GET:
    default:
        methodName = "get_"+fieldName;
        methodReturnType = fieldType;
        headerText = "Get the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return the value of "+fieldName;
        break;
    }

    // set header
    CPPCodeDocumentation * header = new CPPCodeDocumentation(doc);
    if(!getParentObject()->getDoc().isEmpty())
        header->setText(headerText);
    setComment(header);

    // set start method text (EndText never changes)
    setStartMethodText(methodReturnType+' '+className+"::"+methodName+" ("+methodParams+')' + " {");

    setOverallIndentationLevel(0);

    // these ONLY appear if they arent inline
    if(isInlineMethod)
        setWriteOutText(false);

}
コード例 #20
0
void RubyCodeAccessorMethod::updateMethodDeclaration()
{

    RubyCodeClassField * rubyfield = dynamic_cast<RubyCodeClassField*>(getParentClassField());
    RubyClassifierCodeDocument * rubydoc = dynamic_cast<RubyClassifierCodeDocument*>(rubyfield->getParentDocument());

    // gather defs
    CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
    CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAttributeAccessorScope();
    QString strVis = rubydoc->scopeToRubyDecl(rubyfield->getVisibility());
    QString fieldName = RubyCodeGenerator::cppToRubyName(rubyfield->getFieldName());
    QString fieldType = RubyCodeGenerator::cppToRubyType(rubyfield->getTypeName());
    QString objectType = rubyfield->getListObjectType();
    if(objectType.isEmpty())
        objectType = fieldName;
    QString endLine = p->getNewLineEndingChars();

    QString description = getParentObject()->getDoc();
    description.replace(QRegExp("m_[npb](?=[A-Z])"), "");
    description.replace("m_", "");
    description.replace(QRegExp("[\\n\\r]+[\\t ]*"), endLine);

    // set scope of this accessor appropriately..if its an attribute,
    // we need to be more sophisticated
    if(rubyfield->parentIsAttribute())
        switch (scopePolicy) {
        case CodeGenerationPolicy::Public:
        case CodeGenerationPolicy::Private:
        case CodeGenerationPolicy::Protected:
            strVis = rubydoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy);
            break;
        default:
        case CodeGenerationPolicy::FromParent:
            // do nothing..already have taken parent value
            break;
        }

    // some variables we will need to populate
    QString headerText = "";
    QString methodReturnType = "";
    QString methodName = "";
    QString methodParams = "";

    switch(getType()) {
    case CodeAccessorMethod::ADD:
        methodName = "add" + Codegen_Utils::capitalizeFirstLetter(fieldType);
        methodReturnType = "";
        methodParams = objectType+" value ";
        headerText = "Add an object of type "+objectType+" to the Array "+fieldName+endLine+description+endLine+"@return nil";
        setStartMethodText("def "+ methodName + '(' + methodParams + ')');
        setEndMethodText("end");
        break;
    case CodeAccessorMethod::GET:
        headerText = "Get the value of " + fieldName + endLine + description;
        setStartMethodText(QString("attr_reader :") + fieldName);
        setEndMethodText("");
        break;
    case CodeAccessorMethod::LIST:
        methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldType)+"List";
        methodReturnType = "";
        headerText = "Get the list of "+fieldName+endLine+description+endLine+"_returns_ List of "+fieldName;
        setStartMethodText("def "+ methodName + '(' + methodParams + ')');
        setEndMethodText("end");
        break;
    case CodeAccessorMethod::REMOVE:
        methodName = "remove" + Codegen_Utils::capitalizeFirstLetter(fieldType);
        methodReturnType = "";
        methodParams = objectType+" value ";
        headerText = "Remove an object of type "+objectType+" from the List "+fieldName+endLine+description;
        setStartMethodText("def "+ methodName + '(' + methodParams + ')');
        setEndMethodText("end");
        break;
    case CodeAccessorMethod::SET:
        headerText = "Set the value of " + fieldName + endLine + description;
        setStartMethodText(QString("attr_writer :") + fieldName);
        setEndMethodText("");
        break;
    default:
        // do nothing..no idea what this is
        kWarning()<<"Warning: can't generate RubyCodeAccessorMethod for type: "<<getType()<<endl;
        break;
    }

    // set header once.
    if (getComment()->getText().isEmpty())
        getComment()->setText(headerText);

}
コード例 #21
0
void Fac3DDecomposer::fillTextureCoordinates(int id, float* buffer, int bufferLength)
{
    int parentFigure = 0;
    int* pparentFigure = &parentFigure;
    int parent = 0;
    int* pparent = &parent;

    double* colors = NULL;
    double* colormap = NULL;
    double* z = NULL;

    double color = 0.;

    int numVerticesPerGon = 0;
    int* piNumVerticesPerGon = &numVerticesPerGon;
    int numGons = 0;
    int* piNumGons = &numGons;
    int numColors = 0;
    int* piNumColors = &numColors;

    int colormapSize = 0;
    int* piColormapSize = &colormapSize;

    int colorFlag = 0;
    int* piColorFlag = &colorFlag;

    int dataMapping =  0;
    int* piDataMapping = &dataMapping;

    int perVertex = 0;


    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES_PER_GON__, jni_int, (void**) &piNumVerticesPerGon);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_GONS__, jni_int, (void**) &piNumGons);

    getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_COLORS__, jni_int, (void**) &piNumColors);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_COLORS__, jni_double_vector, (void**) &colors);


    parent = getParentObject(id);

    /* Temporary: to avoid getting a null parent_figure property when the object is built */
    if (parent == 0)
    {
        return;
    }

    getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_int, (void**) &pparentFigure);

    if (parentFigure == 0)
    {
        return;
    }

    getGraphicObjectProperty(id, __GO_COLOR_FLAG__, jni_int, (void**) &piColorFlag);
    getGraphicObjectProperty(id, __GO_DATA_MAPPING__, jni_int, (void**) &piDataMapping);

    /* Do not fill */
    if (colorFlag == 0)
    {
        return;
    }

    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);

    if (numColors == numGons * numVerticesPerGon)
    {
        perVertex = 1;
    }
    else if (numColors == numGons)
    {
        perVertex = 0;
    }


    getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_int, (void**) &z);

    if (colorFlag == 1)
    {
        fillNormalizedZColorsTextureCoordinates(buffer, bufferLength, colormap, colormapSize, z, numGons, numVerticesPerGon);
    }
    else if (colorFlag > 1 && numColors == 0)
    {
        /*
         * The color buffer must be filled with the color_mode value.
         * To do: correctly take into account Nan and infinite values.
         */
        int colorMode = 0;
        int* piColorMode = &colorMode;

        getGraphicObjectProperty(id, __GO_COLOR_MODE__, jni_int, (void**) &piColorMode);

        color = (double) colorMode;
        color = DecompositionUtils::getAbsoluteValue(color);

        fillConstantColorsTextureCoordinates(buffer, bufferLength, colormap, colormapSize,
                                             color, numGons, numVerticesPerGon);
    }
    else
    {
        fillDataColorsTextureCoordinates(buffer, bufferLength, colormap, colormapSize,
                                         colors, colorFlag, perVertex, dataMapping, numGons, numVerticesPerGon);
    }

    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);
}
コード例 #22
0
ファイル: codeoperation.cpp プロジェクト: Elv13/Umbrello-ng
UMLOperation * CodeOperation::getParentOperation( )
{
    return dynamic_cast<UMLOperation*>(getParentObject());
}
コード例 #23
0
ファイル: dcodeaccessormethod.cpp プロジェクト: KDE/umbrello
void DCodeAccessorMethod::updateMethodDeclaration()
{
    DCodeClassField * dfield = dynamic_cast<DCodeClassField*>(getParentClassField());

    // Check for dynamic casting failure!
    if (dfield == 0)
    {
        uError() << "dfield: invalid dynamic cast";
        return;
    }

    CodeGenerationPolicy *commonpolicy = UMLApp::app()->commonPolicy();

    // gather defs
    Uml::Visibility::Enum scopePolicy = commonpolicy->getAttributeAccessorScope();
    QString strVis = Uml::Visibility::toString(dfield->getVisibility());
    QString fieldName = dfield->getFieldName();
    QString fieldType = dfield->getTypeName();
    QString objectType = dfield->getListObjectType();
    if(objectType.isEmpty())
        objectType = fieldName;
    QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();

    // set scope of this accessor appropriately..if its an attribute,
    // we need to be more sophisticated
    if (dfield->parentIsAttribute()) {
        switch (scopePolicy) {
        case Uml::Visibility::Public:
        case Uml::Visibility::Private:
        case Uml::Visibility::Protected:
              strVis = Uml::Visibility::toString(scopePolicy);
            break;
        default:
        case Uml::Visibility::FromParent:
            // do nothing..already have taken parent value
            break;
        }
    }

    // some variables we will need to populate
    QString headerText;
    QString methodReturnType;
    QString methodName;
    QString methodParams;

    switch(getType()) {
    case CodeAccessorMethod::ADD:
        methodName = QLatin1String("add") + Codegen_Utils::capitalizeFirstLetter(fieldType);
        methodReturnType = QLatin1String("void");
        methodParams = objectType + QLatin1String(" value ");
        headerText = QLatin1String("Add an object of type ") + objectType + QLatin1String(" to the List ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return void");
        break;
    case CodeAccessorMethod::GET:
        methodName = QLatin1String("get") + Codegen_Utils::capitalizeFirstLetter(fieldName);
        methodReturnType = fieldType;
        headerText = QLatin1String("Get the value of ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return the value of ") + fieldName;
        break;
    case CodeAccessorMethod::LIST:
        methodName = QLatin1String("get") + Codegen_Utils::capitalizeFirstLetter(fieldType) + QLatin1String("List");
        methodReturnType = QLatin1String("List");
        headerText = QLatin1String("Get the list of ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return List of ") + fieldName;
        break;
    case CodeAccessorMethod::REMOVE:
        methodName = QLatin1String("remove") + Codegen_Utils::capitalizeFirstLetter(fieldType);
        methodReturnType = QLatin1String("void");
        methodParams = objectType + QLatin1String(" value ");
        headerText = QLatin1String("Remove an object of type ") + objectType + QLatin1String(" from the List ") + fieldName + endLine + getParentObject()->doc();
        break;
    case CodeAccessorMethod::SET:
        methodName = QLatin1String("set") + Codegen_Utils::capitalizeFirstLetter(fieldName);
        methodReturnType = QLatin1String("void");
        methodParams = fieldType + QLatin1String(" value ");
        headerText = QLatin1String("Set the value of ") + fieldName + endLine + getParentObject()->doc() + endLine;
        break;
    default:
        // do nothing..no idea what this is
        uWarning()<<"Warning: cant generate DCodeAccessorMethod for type: "<<getType();
        break;
    }

    // set header once.
    if(getComment()->getText().isEmpty())
        getComment()->setText(headerText);

    // set start/end method text
    setStartMethodText(strVis + QLatin1Char(' ') + methodReturnType + QLatin1Char(' ') + methodName + QLatin1String(" (") + methodParams + QLatin1String(") {"));
    setEndMethodText(QLatin1String("}"));
}
コード例 #24
0
ファイル: codeoperation.cpp プロジェクト: KDE/umbrello
UMLOperation * CodeOperation::getParentOperation()
{
    return getParentObject()->asUMLOperation();
}
コード例 #25
0
// we basically want to update the start text of this method
void CPPSourceCodeAccessorMethod::updateMethodDeclaration()
{
    CodeClassField * parentField = getParentClassField();
    ClassifierCodeDocument * doc = parentField->getParentDocument();
    CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
    CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);

    // Check for dynamic casting failure!
    if (policy == NULL)
    {
        uError() << "policy: invalid dynamic cast";
        return;
    }

    CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);

    // Check for dynamic casting failure!
    if (cppfield == NULL)
    {
        uError() << "cppfield: invalid dynamic cast";
        return;
    }

    UMLClassifier * c = doc->getParentClassifier();

    bool isInlineMethod = policy->getAccessorsAreInline();
    QString tag = policy->getDocToolTag();

    QString vectorClassName = policy->getVectorClassName();
    QString fieldName = cppfield->getFieldName();
    QString fieldType = cppfield->getTypeName();
    QString objectType = cppfield->getListObjectType();
    if(objectType.isEmpty())
        objectType = fieldName;

    QString methodReturnType(QLatin1String("void"));
    QString methodName; // QLatin1String("get") + cppdoc->capitalizeFirstLetter(fieldName);
    QString methodParams = QChar(QLatin1Char(' ')); // QLatin1String("get") + cppdoc->capitalizeFirstLetter(fieldName);
    QString headerText;
    QString className = CodeGenerator::cleanName(c->name());
    QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();

    switch(getType()) {
    case CodeAccessorMethod::ADD:
        methodName = QLatin1String("add_") + fieldType;
        methodReturnType = QLatin1String("void");
        methodParams = objectType + QLatin1String(" value ");
        headerText = QLatin1String("Add a ") + fieldName + QLatin1String(" object to the ") + fieldName + QLatin1String("List") + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return void");
        break;
    case CodeAccessorMethod::REMOVE:
        methodName = QLatin1String("remove_") + fieldType;
        methodParams = objectType + QLatin1String(" value ");
        methodReturnType = QLatin1String("void");
        headerText = QLatin1String("Remove a ") + fieldName + QLatin1String(" object from the ") + fieldName + QLatin1String("List") + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return void");
        break;
    case CodeAccessorMethod::LIST:
        methodName = QLatin1String("get_") + fieldType + QLatin1String("_list");
        methodReturnType = vectorClassName;
        headerText = QLatin1String("Get the ") + fieldName + QLatin1String("List") + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return ") + vectorClassName + QLatin1String("with list of objects");
        break;
    case CodeAccessorMethod::SET:
        methodName = QLatin1String("set_") + fieldName;
        methodParams = fieldType + QLatin1String(" value ");
        methodReturnType = QLatin1String("void");
        headerText = QLatin1String("Set the value of ") + fieldName + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("param value the value of ") + fieldName;
        break;
    case CodeAccessorMethod::GET:
    default:
        methodName = QLatin1String("get_") + fieldName;
        methodReturnType = fieldType;
        headerText = QLatin1String("Get the value of ") + fieldName + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return the value of ") + fieldName;
        break;
    }

    // set header
    CPPCodeDocumentation * header = new CPPCodeDocumentation(doc);
    if(!getParentObject()->doc().isEmpty())
        header->setText(headerText);
    setComment(header);

    // set start method text (EndText never changes)
    setStartMethodText(methodReturnType + QLatin1Char(' ') + className + QLatin1String("::") + methodName + QLatin1String(" (") + methodParams + QLatin1Char(')') + QLatin1String(" {"));

    setOverallIndentationLevel(0);

    // these ONLY appear if they arent inline
    if(isInlineMethod)
        setWriteOutText(false);

}
コード例 #26
0
void JavaCodeAccessorMethod::updateMethodDeclaration()
{

    JavaCodeClassField * javafield = dynamic_cast<JavaCodeClassField*>(getParentClassField());
    JavaClassifierCodeDocument * javadoc = dynamic_cast<JavaClassifierCodeDocument*>(javafield->getParentDocument());
    CodeGenerationPolicy *commonpolicy = UMLApp::app()->getCommonPolicy();

    // gather defs
    CodeGenerationPolicy::ScopePolicy scopePolicy = commonpolicy->getAttributeAccessorScope();
    QString strVis = javadoc->scopeToJavaDecl(javafield->getVisibility());
    QString fieldName = javafield->getFieldName();
    QString fieldType = javafield->getTypeName();
    QString objectType = javafield->getListObjectType();
    if(objectType.isEmpty())
        objectType = fieldName;
    QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();

    // set scope of this accessor appropriately..if its an attribute,
    // we need to be more sophisticated
    if(javafield->parentIsAttribute())
        switch (scopePolicy) {
        case CodeGenerationPolicy::Public:
        case CodeGenerationPolicy::Private:
        case CodeGenerationPolicy::Protected:
              strVis = javadoc->scopeToJavaDecl((Uml::Visibility::Value) scopePolicy);
            break;
        default:
        case CodeGenerationPolicy::FromParent:
            // do nothing..already have taken parent value
            break;
        }

    // some variables we will need to populate
    QString headerText = "";
    QString methodReturnType = "";
    QString methodName = "";
    QString methodParams = "";

    switch(getType()) {
    case CodeAccessorMethod::ADD:
        methodName = "add" + Codegen_Utils::capitalizeFirstLetter(fieldType);
        methodReturnType = "void";
        methodParams = objectType+" value ";
        headerText = "Add an object of type "+objectType+" to the List "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return void";
        break;
    case CodeAccessorMethod::GET:
        methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldName);
        methodReturnType = fieldType;
        headerText = "Get the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return the value of "+fieldName;
        break;
    case CodeAccessorMethod::LIST:
        methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldType)+"List";
        methodReturnType = "List";
        headerText = "Get the list of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return List of "+fieldName;
        break;
    case CodeAccessorMethod::REMOVE:
        methodName = "remove" + Codegen_Utils::capitalizeFirstLetter(fieldType);
        methodReturnType = "void";
        methodParams = objectType+" value ";
        headerText = "Remove an object of type "+objectType+" from the List "+fieldName+endLine+getParentObject()->getDoc();
        break;
    case CodeAccessorMethod::SET:
        methodName = "set" + Codegen_Utils::capitalizeFirstLetter(fieldName);
        methodReturnType = "void";
        methodParams = fieldType + " value ";
        headerText = "Set the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine;
        break;
    default:
        // do nothing..no idea what this is
        kWarning()<<"Warning: cant generate JavaCodeAccessorMethod for type: "<<getType()<<endl;
        break;
    }

    // set header once.
    if(getComment()->getText().isEmpty())
        getComment()->setText(headerText);

    // set start/end method text
    setStartMethodText(strVis+' '+methodReturnType+' '+methodName+" ( "+methodParams+" ) {");
    setEndMethodText("}");

}
コード例 #27
0
ファイル: sci_delete.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
int sci_delete(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    long long* l1 = NULL;
    int* piAddrl2 = NULL;
    char* l2 = NULL;

    int m1 = 0, n1 = 0, lw = 0;
    unsigned long hdl = 0;
    int nb_handles = 0, i = 0, dont_overload = 0;
    int iObjUID = 0;
    int iFigureUID = 0;
    int* piChildrenUID = NULL;
    int iChildrenCount = 0;
    int* childrencount = &iChildrenCount;
    int iHidden = 0;
    int *piHidden = &iHidden;

    int iParentUID = 0;
    int* piParentUID = &iParentUID;
    int iParentType = -1;
    int *piParentType = &iParentType;
    int iObjType = -1;
    int *piObjType = &iObjType;

    CheckInputArgument(pvApiCtx, 0, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if (nbInputArgument(pvApiCtx) == 0)               /* Delete current object */
    {
        iObjUID = getCurrentObject();
        if (iObjUID == 0)
        {
            //No current object, we can leave
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }

        hdl = (unsigned long)getHandle(iObjUID);
        dont_overload = 1;
        nb_handles = 1;
    }
    else
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        switch (getInputArgumentType(pvApiCtx, 1))
        {
            case sci_matrix:
            {
                if (isEmptyMatrix(pvApiCtx, piAddrl1))
                {
                    AssignOutputVariable(pvApiCtx, 1) = 0;
                    ReturnArguments(pvApiCtx);
                    return 1;
                }
                else
                {
                    Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                    return 1;
                }
                break;
            }
            case sci_handles:      /* delete Entity given by a handle */

                // Retrieve a matrix of handle at position 1.
                sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &m1, &n1, &l1); /* Gets the Handle passed as argument */
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                    return 1;
                }

                nb_handles = m1 * n1;

                if (nbInputArgument(pvApiCtx) == 2)
                {
                    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        return 1;
                    }

                    // Retrieve a matrix of double at position 2.
                    if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))   /* Gets the command name */
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
                        return 1;
                    }
                }
                hdl = (unsigned long) * (l1); /* Puts the value of the Handle to hdl */
                break;
            case sci_strings:      /* delete("all") */
                CheckInputArgument(pvApiCtx, 1, 1);
                sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl2);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                // Retrieve a matrix of double at position 1.
                if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                    return 1;
                }

                if (strcmp((l2), "all") == 0)
                {
                    int i = 0;
                    int iFigureNumber = sciGetNbFigure();

                    if (iFigureNumber == 0)
                    {
                        //no graphic windows, we can leave
                        AssignOutputVariable(pvApiCtx, 1) = 0;
                        ReturnArguments(pvApiCtx);
                        return 0;
                    }

                    iFigureUID = getCurrentFigure();

                    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&childrencount);

                    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);

                    for (i = 0; i < childrencount[0]; ++i)
                    {
                        getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
                        if (iHidden == 0)
                        {
                            deleteGraphicObject(piChildrenUID[i]);
                        }
                    }
                    /*
                     * Clone a new Axes object using the Axes model which is then
                     * attached to the 'cleaned' Figure.
                     */
                    cloneAxesModel(iFigureUID);

                    AssignOutputVariable(pvApiCtx, 1) = 0;
                    ReturnArguments(pvApiCtx);

                    return 0;
                }
                else
                {
                    Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 1, "all");
                    return 0;
                }
                break;
            default:
                // Overload
                lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
                C2F(overload) (&lw, "delete", 6);
                return 0;
        }
    }

    for (i = 0; i < nb_handles; i++)
    {
        int iTemp = 0;
        if (nbInputArgument(pvApiCtx) != 0)
        {
            hdl = (unsigned long) * (l1 + i); /* Puts the value of the Handle to hdl */
        }

        iObjUID = getObjectFromHandle(hdl);

        if (iObjUID == 0)
        {
            Scierror(999, _("%s: The handle is not valid.\n"), fname);
            return 0;
        }

        if (isFigureModel(iObjUID) || isAxesModel(iObjUID))
        {
            Scierror(999, _("This object cannot be deleted.\n"));
            return 0;
        }

        /* Object type */
        getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **)&piObjType);
        if (iObjType == __GO_AXES__)
        {
            /* Parent object */
            iParentUID = getParentObject(iObjUID);
            /* Parent type */
            getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
        }

        if (iObjType == __GO_LABEL__)
        {
            Scierror(999, _("A Label object cannot be deleted.\n"));
            return 0;
        }

        //bug #11485 : duplicate pobjUID before delete it.
        iTemp = iObjUID;
        deleteGraphicObject(iObjUID);

        /*
         ** All figure must have at least one axe child.
         ** If the last one is removed, add a new default one.
         */
        if (iObjType == __GO_AXES__ && iParentType == __GO_FIGURE__)
        {
            int iChild = 0;
            int iChildCount = 0;
            int *piChildCount = &iChildCount;
            char **pstChildren = NULL;
            int iChildType = -1;
            int *piChildType = &iChildType;
            int iAxesFound = 0;
            int iDefaultAxes = -1;
            int *piDefaultAxes = &iDefaultAxes;

            getGraphicObjectProperty(iParentUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&piChildCount);
            getGraphicObjectProperty(iParentUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);
            getGraphicObjectProperty(iParentUID, __GO_DEFAULT_AXES__, jni_bool, (void **)&piDefaultAxes);

            for (iChild = 0; iChild < iChildCount; iChild++)
            {
                getGraphicObjectProperty(piChildrenUID[iChild], __GO_TYPE__, jni_int, (void **)&piChildType);
                if (iChildType == __GO_AXES__)
                {
                    if (getCurrentSubWin() == iTemp) // Current axes has been deleted
                    {
                        setCurrentSubWin(piChildrenUID[iChild]);
                    }
                    iAxesFound = 1;
                    break;
                }
            }
            if (!iAxesFound && iDefaultAxes != 0)
            {

                /*
                 * Clone a new Axes object using the Axes model which is then
                 * attached to the newly created Figure.
                 */
                cloneAxesModel(iParentUID);
            }
        }
    }

    if (!dont_overload)
    {
        // Overload
        lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
        C2F(overload) (&lw, "delete", 6);
    }
    else
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
    }

    if (l2)
    {
        freeAllocatedSingleString(l2);
    }

    return 0;
}
コード例 #28
0
/**
 * This will be called by syncToParent whenever the parent object is "modified".
 */
void DCodeClassFieldDeclarationBlock::updateContent()
{
    CodeClassField * cf = getParentClassField();
    DCodeClassField * jcf = dynamic_cast<DCodeClassField*>(cf);

    if (!jcf)
    {
       uError() << "jcf: invalid dynamic cast";
       return;
    }

    CodeGenerationPolicy * commonpolicy = UMLApp::app()->commonPolicy();

    Uml::Visibility::Enum scopePolicy = commonpolicy->getAssociationFieldScope();

    // Set the comment
    QString notes = getParentObject()->doc();
    getComment()->setText(notes);

    // Set the body
    QString staticValue = getParentObject()->isStatic() ? QLatin1String("static ") : QString();
    QString scopeStr = Uml::Visibility::toString(getParentObject()->visibility());

    // IF this is from an association, then scope taken as appropriate to policy
    if (!jcf->parentIsAttribute())
    {
        switch (scopePolicy) {
        case Uml::Visibility::Public:
        case Uml::Visibility::Private:
        case Uml::Visibility::Protected:
              scopeStr = Uml::Visibility::toString(scopePolicy);
            break;
        default:
        case Uml::Visibility::FromParent:
            // do nothing here... will leave as from parent object
            break;
        }
    }

    QString typeName = jcf->getTypeName();
    QString fieldName = jcf->getFieldName();
    QString initialV = jcf->getInitialValue();

    if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue())
        typeName = QLatin1String("List");

    QString body = staticValue + scopeStr + QLatin1Char(' ') + typeName + QLatin1Char(' ') + fieldName;
    if (!initialV.isEmpty())
        body.append(QLatin1String(" = ") + initialV);
    else if (!cf->parentIsAttribute())
    {
        UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject());

        // Check for dynamic casting failure!
        if (role == NULL)
        {
            uError() << "role: invalid dynamic cast";
            return;
        }

        if (role->object()->baseType() == UMLObject::ot_Interface)
        {
            // do nothing.. can't instantiate an interface
        } else {

            // FIX?: IF a constructor method exists in the classifiercodedoc
            // of the parent Object, then we can use that instead (if its empty).
            if(cf->fieldIsSingleValue())
            {
                if(!typeName.isEmpty())
                    body.append(QLatin1String(" = new ") + typeName + QLatin1String(" ()"));
            } else
                body.append(QLatin1String(" = new Vector ()"));
        }
    }

    setText(body + QLatin1Char(';'));

}