class PointCloudSerializerStep(WorkflowStepMountPoint):
    '''
    A step satisfies the step plugin duck.
    
    It stores point cloud data.
    It can be used as a point cloud data store.
    '''
    def __init__(self, location):
        '''
        Constructor
        '''
        super(PointCloudSerializerStep, self).__init__('Point Cloud Serializer', location)
#        self._name = 'Point Cloud Store'
#        self._location = location
        self._icon = QtGui.QImage(':/pointcloudserializer/images/pointcloudserializer.png')
        self.addPort(('http://physiomeproject.org/workflow/1.0/rdf-schema#port', 'http://physiomeproject.org/workflow/1.0/rdf-schema#uses', 'http://physiomeproject.org/workflow/1.0/rdf-schema#pointcloud'))
        self._state = ConfigureDialogState()
        self._category = 'Sink'
        self._dataIn = None

    def configure(self):
        d = ConfigureDialog(self._state)
        d.setModal(True)
        if d.exec_():
            self._state = d.getState()

        self._configured = d.validate()
        if self._configured and self._configuredObserver != None:
            self._configuredObserver()

    def getIdentifier(self):
        return self._state.identifier()

    def setIdentifier(self, identifier):
        self._state.setIdentifier(identifier)

    def serialize(self, location):
        if not os.path.exists(self.getOutputDirectory()):
            os.mkdir(self.getOutputDirectory())

        configuration_file = os.path.join(location, getConfigFilename(self._state.identifier()))
        s = QtCore.QSettings(configuration_file, QtCore.QSettings.IniFormat)
        self._state.save(s)

    def deserialize(self, location):
        configuration_file = os.path.join(location, getConfigFilename(self._state.identifier()))
        s = QtCore.QSettings(configuration_file, QtCore.QSettings.IniFormat)
        self._state.load(s)
        d = ConfigureDialog(self._state)
        self._configured = d.validate()

    def getOutputDirectory(self):
        return os.path.join(self._location, self._state.identifier())

    def setPortData(self, portId, dataIn):
        self._dataIn = dataIn

    def execute(self):
        if self._dataIn:
            f = open(os.path.join(self.getOutputDirectory(), 'pointcloud.txt'), 'w')
            for i, pt in enumerate(self._dataIn):
                f.write(str(i + 1) + '\t' + str(pt[0]) + '\t' + str(pt[1]) + '\t' + str(pt[2]) + '\n')
            f.close()
        self._doneExecution()