/***************************************************************************\
 *                           Instance methods                              *
\***************************************************************************/
void GenericFieldEditor::internalFieldChanged (void)
{
    GetFieldHandlePtr TheFieldHandle = getEditingFC()->getField(getEditingFieldId());

    if(TheFieldHandle->isPointerField())
    {
        if(TheFieldHandle->getCardinality() == FieldType::SingleField)
        {
            GetSFieldHandle<FieldContainerPtrSFieldBase>* ThePtrFieldHandle(dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get()));
            if(ThePtrFieldHandle->get() != NULL)
            {
                _EditingTextField->setText(boost::lexical_cast<std::string>(ThePtrFieldHandle->get()->getId()));
            }
            else
            {
                _EditingTextField->setText("0");
            }
        }
        else
        {
            GetMFieldHandle<FieldContainerPtrMFieldBase>* ThePtrFieldHandle(dynamic_cast<GetMFieldHandle<FieldContainerPtrMFieldBase>*>(TheFieldHandle.get()));
            if(ThePtrFieldHandle->size() > getEditingFieldIndex() &&
               ThePtrFieldHandle->get(getEditingFieldIndex()) != NULL)
            {
                _EditingTextField->setText(boost::lexical_cast<std::string>(ThePtrFieldHandle->get(getEditingFieldIndex())->getId()));
            }
            else
            {
                _EditingTextField->setText("0");
            }
        }
    }
    else
    {
        std::ostringstream StrStream;
        OutStream TheOutStream(StrStream);
        if(TheFieldHandle->getCardinality() == FieldType::SingleField)
        {
            TheFieldHandle->pushValueToStream(TheOutStream);
        }
        else
        {
            TheFieldHandle->pushIndexedValueToStream(TheOutStream, getEditingFieldIndex());
        }

        //Remove quotes from strings
        if(TheFieldHandle->getType().getContentType() == FieldTraits<std::string>::getType())
        {
            _EditingTextField->setText(StrStream.str().substr(1,StrStream.str().size()-2));
        }
        else
        {
            _EditingTextField->setText(StrStream.str());
        }
    }

}
void SetFieldValueCommand::undo(void)
{
    Inherited::undo();

    //reset the value
    GetFieldHandlePtr TheFieldHandle = _FC->getField(_FieldId);
    if(TheFieldHandle->getCardinality() == FieldType::SingleField)
    {
        if(TheFieldHandle->isPointerField())
        {
            FieldContainer* FC = FieldContainerFactory::the()->getContainer(boost::lexical_cast<UInt32>(_PrevValue));
            dynamic_cast<EditSFieldHandle<FieldContainerPtrSFieldBase>*>(_FC->editField(_FieldId).get())->set(FC);
        }
        else
        {
            _FC->editField(_FieldId)->pushValueFromCString(_PrevValue.c_str());
        }
    }
    else
    {
        if(TheFieldHandle->isPointerField())
        {
            FieldContainer* FC = FieldContainerFactory::the()->getContainer(boost::lexical_cast<UInt32>(_PrevValue));
            dynamic_cast<EditMFieldHandle<FieldContainerPtrMFieldBase>*>(_FC->editField(_FieldId).get())->replace(_Index, FC);
        }
        else
        {
            _FC->editField(_FieldId)->pushIndexedValueFromCString(_PrevValue.c_str(), _Index);
        }
    }
}
/***************************************************************************\
 *                           Instance methods                              *
\***************************************************************************/
void BoolFieldEditor::internalFieldChanged (void)
{

    GetFieldHandlePtr TheFieldHandle = getEditingFC()->getField(getEditingFieldId());
    bool Value;

    if(TheFieldHandle->getCardinality() == FieldType::SingleField)
    {
        Value = static_cast<const SFBool*>(TheFieldHandle->getField())->getValue();
    }
    else
    {
        Value = static_cast<const MFBool*>(TheFieldHandle->getField())->operator[](getEditingFieldIndex());
    }

    if(_EditingCheckbox->getSelected() != Value)
    {
        _ButtonSelectedConnection.disconnect();
        _ButtonDeselectedConnection.disconnect();

        _EditingCheckbox->setSelected(Value);
    }

    _ButtonSelectedConnection = _EditingCheckbox->connectButtonSelected(boost::bind(&BoolFieldEditor::handleButtonSelected, this, _1));
    _ButtonDeselectedConnection = _EditingCheckbox->connectButtonDeselected(boost::bind(&BoolFieldEditor::handleButtonDeselected, this, _1));

}
void BoolFieldEditor::runCommand  (bool value)
{
    bool fieldValue;
    GetFieldHandlePtr TheFieldHandle = getEditingFC()->getField(getEditingFieldId());

    if(TheFieldHandle->getCardinality() == FieldType::SingleField)
    {
        fieldValue = static_cast<const SFBool*>(TheFieldHandle->getField())->getValue();
    }
    else
    {
        fieldValue = static_cast<const MFBool*>(TheFieldHandle->getField())->operator[](getEditingFieldIndex());
    }

    if(value != fieldValue)
    {
        //Call the command to set the Field
        SetFieldValueCommandPtr SetCommand = SetFieldValueCommand::create(getEditingFC(), 
                                                                          getEditingFieldId(), 
                                                                          (value ? "TRUE" : "FALSE"), 
                                                                          getEditingFieldIndex());

        getCommandManager()->executeCommand(SetCommand);
    }
}
void FCPtrFieldEditor::internalFieldChanged (void)
{
    GetFieldHandlePtr TheFieldHandle = getEditingFC()->getField(getEditingFieldId());

    assert(TheFieldHandle->getType().getClass() == FieldType::PtrField ||
           TheFieldHandle->getType().getClass() == FieldType::ChildPtrField);

    //Get the Editing FCPtr
    FieldContainer* EditingFC(NULL);
    if(TheFieldHandle->getCardinality() == FieldType::SingleField)
    {
        GetSFieldHandle<FieldContainerPtrSFieldBase>* ThePtrFieldHandle(dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get()));
        EditingFC = ThePtrFieldHandle->get();
    }
    else
    {
        GetMFieldHandle<FieldContainerPtrMFieldBase>* ThePtrFieldHandle(dynamic_cast<GetMFieldHandle<FieldContainerPtrMFieldBase>*>(TheFieldHandle.get()));
        EditingFC = ThePtrFieldHandle->get(getEditingFieldIndex());
    }

    //Update the Editing Text
    std::string EditingText("NULL");
    std::string Name("");
    std::string TypeName("");

    if(EditingFC != NULL)
    {
        //Get the Id of the FieldContainer
        EditingText = boost::lexical_cast<std::string>(EditingFC->getId());

        //If the FieldContainer has a name attachment then get the name
        if(EditingFC->getType().isDerivedFrom(AttachmentContainer::getClassType()) && 
           getName(dynamic_cast<AttachmentContainer*>(EditingFC)))
        {
            Name = getName(dynamic_cast<AttachmentContainer*>(EditingFC));
        }

        //Get the name of the type of the FieldContainer
        TypeName = EditingFC->getType().getName();
    }


    //Update the Labels and TextFields
    _EditingTextField->setText(EditingText);
    _NameTypeLabel->setText(Name + " [" + TypeName + "]");
}
void TextFieldEditor::internalFieldChanged (void)
{
    GetFieldHandlePtr TheFieldHandle = getEditingFC()->getField(getEditingFieldId());

    std::ostringstream StrStream;
    OutStream TheOutStream(StrStream);
    if(TheFieldHandle->getCardinality() == FieldType::SingleField)
    {
        TheFieldHandle->pushValueToStream(TheOutStream);
    }
    else
    {
        TheFieldHandle->pushIndexedValueToStream(TheOutStream, getEditingFieldIndex());
    }
        
    _EditingTextArea->setText(StrStream.str());

}
void FieldAnimation::changed(ConstFieldMaskArg whichField, 
                             UInt32            origin,
                             BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if(whichField & FieldNameFieldMask)
    {
        if(getContainer() != NULL)
        {

            FieldDescriptionBase * f = getContainer()->getFieldDescription(getFieldName().c_str());
            if( f == NULL )
            {
                SWARNING << "Could not find Field "<< getFieldName() << " in Field Container " << getContainer()->getTypeName()  << std::endl;
                return;
            }
            else
            {
                setFieldId(f->getFieldId());
                //commitChanges();
            }
        }
        else
        {
            SWARNING << "There is no Field Container defined to Animate"  << std::endl;
            return;
        }
    }
    else if((whichField & FieldIdFieldMask) ||
            (whichField & ContainerFieldMask))
    {
        if(getContainer() != NULL)
        {
            FieldDescriptionBase * f = getContainer()->getFieldDescription(getFieldId());
            if( f == NULL )
            {
                SWARNING << "Could not find Field ID"<< getFieldId() << " in Field Container " << getContainer()->getTypeName()  << std::endl;
                return;
            }
            else
            {
                if(getAnimator()->getDataType() == NULL)
                {
                    SWARNING << "Cannot update animation, because the animator attached to this animation does not work on any data types."  << std::endl;
                    return;
                }
                //Check if it's the right type
                if(getContainer()->getFieldDescription(getFieldId())->getFieldType().getContentType()
                   != *getAnimator()->getDataType())
                {
                    SWARNING << "The data type of the field: "
                             << getContainer()->getFieldDescription(getFieldId())->getName()
                             << " with type: "
                             << getContainer()->getFieldDescription(getFieldId())->getFieldType().getContentType().getCName()
                             << " connected to this animation is not the same data type: "
                             << getAnimator()->getDataType()->getCName()
                             << ", that the animator works on."  << std::endl;
                    return;
                }
            }
        }
        else
        {
            SWARNING << "There is no Field Container defined to Animate"  << std::endl;
            return;
        }
    }
    if(whichField & IndexFieldMask)
    {
        if(getContainer() != NULL)
        {
            FieldDescriptionBase * f = getContainer()->getFieldDescription(getFieldId());
            if( f == NULL )
            {
                SWARNING << "Could not find Field ID"<< getFieldId() << " in Field Container " << getContainer()->getTypeName()  << std::endl;
            }
            else
            {

                //Check if animator supports any types
                if(getAnimator()->getDataType() == NULL)
                {
                    SWARNING << "Cannot update animation, because the animator attached to this animation does not work on any data types."  << std::endl;
                }
                //Check if it's the right type
                if(getContainer()->getFieldDescription(getFieldId())->getFieldType().getContentType()
                   != *getAnimator()->getDataType())
                {
                    SWARNING << "The data type of the field: "
                             << getContainer()->getFieldDescription(getFieldId())->getName()
                             << " with type: "
                             << getContainer()->getFieldDescription(getFieldId())->getFieldType().getContentType().getCName()
                             << " connected to this animation is not the same data type: "
                             << getAnimator()->getDataType()->getCName()
                             << ", that the animator works on."  << std::endl;
                }
                GetFieldHandlePtr TheFieldHandle = getContainer()->getField( getFieldId() );

                if( getIndex() > 0 )
                {
                    if(TheFieldHandle->getCardinality() != FieldType::MultiField)
                    {
                        SWARNING << "Cannot attach to index: " << getIndex() 
                                 << " of field " << getContainer()->getFieldDescription(getFieldId())->getName() 
                                 << " because it has cardinality 1." << std::endl;
                    }
                    else if(getIndex() < TheFieldHandle->size())
                    {
                        SWARNING << "Cannot attach to index: " << getIndex() 
                                 << " of field " << getContainer()->getFieldDescription(getFieldId())->getName() 
                                 << " because that index is out of bounds on a field of size " << TheFieldHandle->size() << "." << std::endl;
                    }
                }
            }
        }
        else
        {
            SWARNING << "There is no Field Container defined to Animate"  << std::endl;
        }
    }
}
void SetFieldValueCommand::execute(void)
{
    //Check for a valid Field Container
    if(_FC == NULL)
    {
        SWARNING << "FieldContainer is NULL." << std::endl;
        return;
    }

    //Check for valid Field
    GetFieldHandlePtr TheFieldHandle = _FC->getField(_FieldId);
    if(!TheFieldHandle->isValid())
    {
        SWARNING << "No Field with Id: " << _FieldId << " in FieldContainers of type " << _FC->getType().getName() << std::endl;
        return;
    }

    //Check for valid indexing
    if(TheFieldHandle->getCardinality() == FieldType::SingleField && _Index != 0)
    {
        SWARNING << "Cannot reference index " << _Index << ", on field " << TheFieldHandle->getDescription()->getName() 
                 << ", on FieldContianer of type " << _FC->getType().getName()
                 << " because that field is a SingleField." << std::endl;
        return;
    }
    else if(TheFieldHandle->getCardinality() == FieldType::MultiField && _Index >= TheFieldHandle->size())
    {
        SWARNING << "Cannot set the value of index " << _Index << ", on field " << TheFieldHandle->getDescription()->getName() 
                 << ", on FieldContianer of type " << _FC->getType().getName()
                 << " because that field has size " << TheFieldHandle->size() << std::endl;
        return;
    }


    //Get the previous value
    if(_PrevValue.empty())
    {
        std::ostringstream StrStream;
        OutStream TheOutStream(StrStream);
        if(TheFieldHandle->getCardinality() == FieldType::SingleField)
        {
            if(TheFieldHandle->isPointerField())
            {
                _PrevPtrValue = dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get())->get();
                if(dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get())->get())
                {
                    _PrevValue = boost::lexical_cast<std::string>(dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TheFieldHandle.get())->get()->getId());
                }
                else
                {
                    _PrevValue = "0";
                }
            }
            else
            {
                TheFieldHandle->pushValueToStream(TheOutStream);
                _PrevValue = StrStream.str();
            }
        }
        else
        {
            if(TheFieldHandle->isPointerField())
            {
                _PrevPtrValue = dynamic_cast<GetMFieldHandle<FieldContainerPtrMFieldBase>*>(TheFieldHandle.get())->get(_Index);
                if(_PrevPtrValue)
                {
                    _PrevValue = boost::lexical_cast<std::string>(dynamic_cast<GetMFieldHandle<FieldContainerPtrMFieldBase>*>(TheFieldHandle.get())->get(_Index)->getId());
                }
                else
                {
                    _PrevValue = "0";
                }
            }
            else
            {
                TheFieldHandle->pushIndexedValueToStream(TheOutStream, _Index);
                _PrevValue = StrStream.str();
            }
        }

        //Remove quotes from strings
        if(TheFieldHandle->getType().getContentType() == FieldTraits<std::string>::getType())
        {
            _PrevValue = _PrevValue.substr(1,StrStream.str().size()-2);
        }
    }

    //Set the value
    if(TheFieldHandle->getCardinality() == FieldType::SingleField)
    {
        if(TheFieldHandle->isPointerField())
        {
            _PtrValue = FieldContainerFactory::the()->getContainer(boost::lexical_cast<UInt32>(_Value));
            
            //Check the pointer types match
            if(_PtrValue != NULL &&
                !isFieldContentDerivedFrom(TheFieldHandle->getType(),&_PtrValue->getType()))
            {
                SWARNING << "Cannot set the value of field " << TheFieldHandle->getDescription()->getName() 
                         << ", on FieldContianer of type " << _FC->getType().getName()
                         << " because the value attemting to be set is not derived from the type the field stores." << std::endl;
                return;
            }
            if(_PtrValue != _PrevPtrValue)
            {
                dynamic_cast<EditSFieldHandle<FieldContainerPtrSFieldBase>*>(_FC->editField(_FieldId).get())->set(_PtrValue);
            }
        }
        else
        {
            _FC->editField(_FieldId)->pushValueFromCString(_Value.c_str());
        }
    }
    else
    {
        if(TheFieldHandle->isPointerField())
        {
            _PtrValue = FieldContainerFactory::the()->getContainer(boost::lexical_cast<UInt32>(_Value));
            
            //Check the pointer types match
            if(_PtrValue != NULL && !isFieldContentDerivedFrom(TheFieldHandle->getType(),&_PtrValue->getType()))
            {
                SWARNING << "Cannot set the value of field " << TheFieldHandle->getDescription()->getName() 
                         << ", on FieldContianer of type " << _FC->getType().getName()
                         << " because the value attemting to be set is not derived from the type the field stores." << std::endl;
                return;
            }
            if(_PtrValue != _PrevPtrValue)
            {
                dynamic_cast<EditMFieldHandle<FieldContainerPtrMFieldBase>*>(_FC->editField(_FieldId).get())->replace(_Index, _PtrValue);
            }
        }
        else
        {
            _FC->editField(_FieldId)->pushIndexedValueFromCString(_Value.c_str(), _Index);
        }
    }

    Inherited::execute();
	_HasBeenDone = true;
}
Example #9
0
void OSGWriter::writeField(GetFieldHandlePtr hF)
{
    if(hF->isValid() == false)
    {
        return;
    }

//    const FieldType& fType = hF->getType();

    GetMapFieldHandlePtr sfMap = 
        boost::dynamic_pointer_cast<
            GetMapFieldHandle>(hF);

    FieldContainerPtrSFieldBase::GetHandlePtr sfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrSFieldBase::GetHandle>(hF);
    
    FieldContainerPtrMFieldBase::GetHandlePtr mfFCPtr = 
        boost::dynamic_pointer_cast<FieldContainerPtrMFieldBase::GetHandle>(hF);

    if(sfMap != NULL && sfMap->isValid() == true)
    {
        _outStream << BeginElem 
                   << hF->getName();

        //if the Attachment Map is empty write [] as its content
        if(sfMap->empty() == true)
        {
            _outStream << " [ ] " << EndElemNL;
        }
        else
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "["
                       << EndElemNL;

            _outStream << IncIndent;
        
            EditMapFieldHandle::MapList fcList;

            sfMap->flatten(fcList);

            EditMapFieldHandle::MapList::iterator iter = fcList.begin();
            EditMapFieldHandle::MapList::iterator end  = fcList.end  ();

            for(; iter!=end; ++iter)
            {
                _outStream << BeginElem
                           << "MapHelper"
                           << EndElemNL
                           << BeginElem
                           << "{"
                           << EndElemNL;

                _outStream << IncIndent;

                _outStream << BeginElem
                           << "keys"
                           << EndElemNL
                           << BeginElem
                           << "["
                           << EndElemNL;

                _outStream << IncIndent;

                std::vector<std::string>::const_iterator kIt  = 
                    iter->first.begin();

                std::vector<std::string>::const_iterator kEnd = 
                    iter->first.end();

                for(; kIt != kEnd; ++kIt)
                {
                    _outStream << BeginElem
                               << "\""
                               << *kIt
                               << "\""
                               << EndElemNL;
                }

                _outStream << DecIndent;

                _outStream << BeginElem
                           << "]"
                           << EndElemNL;

                _outStream << BeginElem
                           << "container ";
                    
                if(iter->second == NULL)
                {
                    _outStream << "NULL"
                               << EndElemNL;
                }
                else
                {
                    writeContainer(iter->second, false);
                    _outStream << EndElemNL;
                }

                _outStream << DecIndent;
                                    
                _outStream << BeginElem
                           << "}"
                           << EndElemNL;
            }

            _outStream << DecIndent; 
            
            _outStream << BeginElem
                       << "]"
                       << EndElemNL;
        }
    }
    else if(sfFCPtr != NULL || mfFCPtr != NULL)
    {
        //this Field points to FC

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem 
                       << hF->getName();
        }

        if(sfFCPtr != NULL && sfFCPtr->isValid() == true)
        {
            if((*sfFCPtr)->getValue() == NULL)
            {
                _outStream << " NULL" << EndElemNL;
            }
            else
            {
                _outStream << " ";
                writeContainer((*sfFCPtr)->getValue(), false);
            }
        }
        else if(mfFCPtr != NULL && mfFCPtr->isValid() == true)
        {
            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

            SizeT mfSize = (*mfFCPtr)->size();

            for(SizeT i = 0; i < mfSize; i++)
            {
                if((*(*mfFCPtr))[i] == NULL)
                {
                    _outStream << BeginElem
                               << "NULL" 
                               << EndElemNL;
                }
                else
                {
                    writeContainer((*(*mfFCPtr))[i], true);
                }
            }

            _outStream << DecIndent;

            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
    else
    {
        //this Field contains data -> write it out

        if(hF->getDescription()->isDynamic() == true)
        {
            _outStream << BeginElem 
                       << "field "
                       << hF->getType().getCName()
                       << " "
                       << hF->getName();
        }
        else
        {
            _outStream << BeginElem << hF->getName();
        }

        //to access the content of a field via a Field*
        //one must know the cardinality
        if(hF->getCardinality() == FieldType::SingleField)
        {
            _outStream << " ";

            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
        }
        else if(hF->getCardinality() == FieldType::MultiField)
        {
            _outStream << " #";

            hF->pushSizeToStream(_outStream);

            _outStream << EndElemNL
                       << BeginElem
                       << "[" 
                       << EndElemNL;

            _outStream << IncIndent;

#ifdef WFC
            hF->pushValueToStream(_outStream);

            _outStream << EndElemNL;
#endif


            _outStream << DecIndent;
            
            _outStream << BeginElem
                       << "]" 
                       << EndElemNL;
        }
    }
}