/***************************************************************************\
 *                           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());
        }
    }

}
/***************************************************************************\
 *                           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 ImageFieldEditor::openCreateHandler(void)
{
    //Have the user select the file to import
    std::vector<WindowEventProducer::FileDialogFilter> Filters;

    std::list< const Char8 * > ReadableImageSuff;
    ImageFileHandler::the()->getSuffixList(ReadableImageSuff, ImageFileType::OSG_READ_SUPPORTED);
    //Determine all of the readable image filetypes
    Filters.push_back(WindowEventProducer::FileDialogFilter("All Image filetypes",""));
    std::string AllImageSuffixes;
    std::string AllImageSuffixesDesc("All Image filetypes (");
    for(std::list<const Char8*>::const_iterator SuffixItor(ReadableImageSuff.begin()) ; SuffixItor != ReadableImageSuff.end() ; ++SuffixItor)
    {
        if(ImageFileHandler::the()->getFileType(*SuffixItor))
        {
            if(!AllImageSuffixes.empty())
            {
                AllImageSuffixes += ",";
                AllImageSuffixesDesc += ", ";
            }
            AllImageSuffixes += *SuffixItor;
            AllImageSuffixesDesc = AllImageSuffixesDesc + "*." + *SuffixItor;
            Filters.push_back(WindowEventProducer::FileDialogFilter(std::string(ImageFileHandler::the()->getFileType(*SuffixItor)->getMimeType()) +  " (*." + *SuffixItor + ")",*SuffixItor));
        }
    }
    AllImageSuffixesDesc += ")";
    Filters[0] = WindowEventProducer::FileDialogFilter(AllImageSuffixesDesc,AllImageSuffixes);
    Filters.push_back(WindowEventProducer::FileDialogFilter("All (*.*)","*"));

    std::vector<BoostPath> FilesToOpen;
    FilesToOpen = getParentWindow()->getParentDrawingSurface()->getEventProducer()->openFileDialog("Import a image file.",
                                                                          Filters,
                                                                          BoostPath("."),
                                                                          false);

    ImageRefPtr NewImage = NULL;

    if(FilesToOpen.size() > 0)
    {
        //Try loading the file using the ImageFileHandler
        NewImage = ImageFileHandler::the()->read(FilesToOpen[0].string().c_str());

        if(NewImage)
        {
            FilePathAttachment::setFilePath(NewImage, FilesToOpen[0]);

            //Set the value of the field
            SetFieldValueCommandPtr SetCommand =
                SetFieldValueCommand::create(getEditingFC(),
                                             getEditingFieldId(),
                                             boost::lexical_cast<std::string>(NewImage->getId()),
                                             getEditingFieldIndex());

            getCommandManager()->executeCommand(SetCommand);
        }
    }
}
void FCPtrFieldEditor::handleFindContainerDialogClosed(DialogWindowEventDetails* const details)
{
    if(details->getOption() != DialogWindowEventDetails::DIALOG_OPTION_CANCEL)
    {
        FCPtrEditorStore::FieldContianerVector fcStore(_FindFCStore->getList());
        //Set the value of the field
        SetFieldValueCommandPtr SetCommand =
            SetFieldValueCommand::create(getEditingFC(),
                                         getEditingFieldId(),
                                         boost::lexical_cast<std::string>(fcStore[details->getInputIndex()]->getId()),
                                         getEditingFieldIndex());

        getCommandManager()->executeCommand(SetCommand);
    }
    _FindContainerDialogClosedConnection.disconnect();
}
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 FCPtrFieldEditor::handleCreateContainerDialogClosed(DialogWindowEventDetails* const details)
{
    if(details->getOption() != DialogWindowEventDetails::DIALOG_OPTION_CANCEL)
    {
        const FieldContainerType* ThePtrType(getFieldContainerTypeFromPtrType(getEditingFC()->getFieldDescription(getEditingFieldId())->getFieldType().getContentType()));

        const FieldContainerType* TheType(FieldContainerFactory::the()->findType(details->getInput().c_str()));

        if(TheType != NULL)
        {
            //Create the Container
            CreateFieldContainerCommandPtr CreateCommand;
            
            //If the type is a node, then create a NodeCore instead
            //and then insert it as the core of a newly created node
            if(*ThePtrType == Node::getClassType())
            {
                CreateFieldContainerCommandPtr CreateCoreCommand = CreateFieldContainerCommand::create(TheType);
                getCommandManager()->executeCommand(CreateCoreCommand);
                
                CreateCommand = CreateFieldContainerCommand::create(&Node::getClassType());
                getCommandManager()->executeCommand(CreateCommand);

                dynamic_cast<Node*>(CreateCommand->getContainer())->setCore(dynamic_cast<NodeCore*>(CreateCoreCommand->getContainer()));
            }
            else
            {
                CreateCommand = CreateFieldContainerCommand::create(TheType);
                getCommandManager()->executeCommand(CreateCommand);
            }

            //Set the value of the field
            SetFieldValueCommandPtr SetCommand =
                SetFieldValueCommand::create(getEditingFC(),
                                             getEditingFieldId(),
                                             boost::lexical_cast<std::string>(CreateCommand->getContainer()->getId()),
                                             getEditingFieldIndex());

            getCommandManager()->executeCommand(SetCommand);
        }
    }
    _CreateContainerDialogClosedConnection.disconnect();
}
void TextFieldEditor::internalStopEditing  (void)
{
    //Call the command to set the Field
    SetFieldValueCommandPtr SetCommand = SetFieldValueCommand::create(getEditingFC(), getEditingFieldId(), _EditingTextArea->getText(), getEditingFieldIndex());

    getCommandManager()->executeCommand(SetCommand);
}
Пример #10
0
void FCPtrFieldEditor::internalStopEditing  (void)
{
    std::string FCId(_EditingTextField->getText());
    if(_EditingTextField->getText().compare("NULL") == 0)
    {
        FCId = "0";
    }
    else
    {
        //Make sure the Id can be cast to a UInt32
        try
        {
            UInt32 CastTest = boost::lexical_cast<UInt32>(FCId);
        }
        catch(boost::bad_lexical_cast &)
        {
            //If it can't then cancel editing
            internalCancelEditing();
            return;
        }
    }

    //Call the command to set the Field
    SetFieldValueCommandPtr SetCommand = SetFieldValueCommand::create(getEditingFC(), getEditingFieldId(), FCId, getEditingFieldIndex());

    getCommandManager()->executeCommand(SetCommand);
}